Alfred__Lee 发表于 2013-1-6 02:22:06

单例设计demo

单例设计demo

<div id="cnblogs_post_body">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();
}
}
页: [1]
查看完整版本: 单例设计demo