1、通过private私有化构造器防止外部创建实例;
2、通过静态代码块创建实例;
3、创建方法返回创建的实例;
饿汉模式:
class sing{
private sing test=new sing();
private sing(){
}
public sing getCase(){//调用该方法返回一个实例
return test;
}
}
懒汉模式(基础版本,不安全):
class sing{
private sing test=null;
private sing(){
}
public sing getCase(){
if(test==null){//判断是否存在实例,不存在则实例化一个
test= new sing();
}
return test;
}
}



