单例使用对象:单例这种设计模式主要是用于一些系统公共资源的开发操作上。
代码模型:
1 class Singleton{ 2 private static final Singleton INSTANCE = new Singleton(); 3 private Singleton(){} 4 public void get(){ 5 System.out.println("单例设计模式"); 6 } 7 public static Singleton getInstance(){ 8 return INSTANCE; 9 } 10 } 11 public class TestDemo{ 12 public static void main(String rags[]){ 13 Singleton s = Singleton.getInstance(); 14 s.get(); 15 } 16 }