通过设置私有构造器,禁止外部类创建该对象实例。本来中有一个静态方法(实例方法),通过访问该实例方法获取同一对象
public class SimpleSingleton {
private static SimpleSingleton instance;
private SimpleSingleton(){}
public static SimpleSingleton getIntance(){
if(instance == null)
instance = new SimpleSingleton();
return instance;
}
}