public class Single {
//构造方法私有化
private Single(){
}
//由于方法是静态的 所以s也要是静态变量 只赋一次初值 私不私有都可以
static Single s=null;
public static Single getInstance()
{
if(s==null)
s=new Single();
return s;
}
}
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Single s1 = Single.getInstance();
Single s2 = Single.getInstance();
System.out.println(s1==s2);
}
}