就是将构造函数变为私有,那么就不能通过new 来创建对象。
同时创建一个共有的静态的方法来获得实例,
代码如下:

class Test...{

private static Test instance = null;


private Test()...{}


public static Test getInstance()...{


if( instance == null )...{
instance = new Test();
}
return instance ; 
}

}
同时创建一个共有的静态的方法来获得实例,
代码如下:




















