public class Test {
public static void main(String[] args){
SingleTon sr=SingleTon.getSingleTon();
System.out.println("-------------");
SingleTon sr1=SingleTon.getSingleTon();
}
}
class SingleTon{
//私有化对象,使之只能存在一个该类对象
private static SingleTon singleTon=new SingleTon();
//私有化构造方法
private SingleTon(){
System.out.println("SingleTon");
}
public static SingleTon getSingleTon(){
return singleTon;
}
}
输出结果为:
SingleTon
-------------
Caballarii
相关分类