饿汉式
public class Single {
private Single(){}
private static Single s = new Single();
public static Single getInstance(){
return s;
}
}
public class SingleTest {
public static void main(String[] args) {
//获取Single类对象,不能new,只能类名调用静态方法获取
Single s = Single.getInstance();
System.out.println(s);
Single s1 = Single.getInstance();
System.out.println(s1);
}
}