一,单例模式
public class Singleton {
private static Singleton s;
private int p;
private Singleton() {
//必要素
}
public static Singleton getInstance() {
if (s == null) {
s = new Singleton();
}
return s;
}
public static void main(String[] args) {
Singleton s1 = Singleton.getInstance();
s1.p = 100;
Singleton s2 = Singleton.getInstance();
System.out.println(s2.p);
}
}