package test.singleton;
/*懶漢式*/
public class singletonOne {
public singletonOne(){
}
private static final singletonOne singOne=new singletonOne();
public static singletonOne getSingOne(){
return singOne;
}
public void showSingletonOne(){
System.out.println("太笨");
}
}
class SingeletonTwo{
public SingeletonTwo(){
}
public static SingeletonTwo singTwo=null;
public static SingeletonTwo getInstance(){
if(singTwo==null){
singTwo =new SingeletonTwo();
}
return singTwo;
}
public void twoTest(){
System.out.println("大懶蛋");
}
}
package test.singleton;
public class singeletonOneTest {
public static void main(String [] args){
singletonOne singeOne=singletonOne.getSingOne();
singeOne.showSingletonOne();
SingeletonTwo two=SingeletonTwo.getInstance();
two.twoTest();
}
}