package com.atguigu.single;
/**
*
*
*
* 懒汉式
*
* 延迟创建这个实例对象
*
*
* 1.构造器私有化
* 2.用一个静态变量保存这个唯一的实例
* 3.提供一个静态方法,获取这个实例对象
*
*
*
* @author chen
*
*/
public class Singleton06 {
private static Singleton06 instance;
private Singleton06(){
}
public static Singleton06 getInstance(){
if(instance == null){
instance = new Singleton06();
}
return instance;
}
}
package com.atguigu.single;
public class testSingleton06 {
public static void main(String[] args){
Singleton06 instance =Singleton06.getInstance();
System.out.println(instance);
}
}