代码改变世界

Java-04-单态模式

2014-04-18 23:48  georgethrax  阅读(122)  评论(0)    收藏  举报

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的唯一实例的引用

  }

}