class A
{
private static final A p =new A();
private A()
{
...
}
public static A getP()
{
return p;
}
}
public class Proj
{
public static void main(String[] args)
{
A p=null;
p=A.getP(); //p获得类A的唯一实例的引用
}
}
class A
{
private static final A p =new A();
private A()
{
...
}
public static A getP()
{
return p;
}
}
public class Proj
{
public static void main(String[] args)
{
A p=null;
p=A.getP(); //p获得类A的唯一实例的引用
}
}