class Singleton{ private static Singleton instance;//类Feild:instance private Singleton()//构造器 {} public static Singleton getInstance()//特殊方法,可以访问构造器 { if (instance == null) { intance = new Singleton(); } return instance; }}public class SingleTest{ public static void main(String[] args) { Singleton s1 = Singleton.getInstance(); Singleton s2 = Singleton.getInstance(); System.out.println(s1==s2); }}