单例设计demo

class Single {
 private static Single instance = new Single();

 private Single() {
 }
 public static Single getInstance() {
  return instance;
 }
 public void print() {
  System.out.println("This is a singleDemo test");
 }
}

public class SingletonDemo {
 
 /**
  * <p> 单例设计</p>
  * <p>使用  "类名.方法名"  调用静态方法</p>
  * @created on 2012-4-24
  */
 public static void main(String args[]) {
  Single s = null;
  s = Single.getInstance();
  s.print();
 }
}

posted on 2012-05-10 19:20  Alfred__Lee  阅读(304)  评论(0)    收藏  举报

导航