设计模式 单例模式
Single类的源码
package com;
public class Single {
private static Single s =new Single();
private Single() //构造方法私有
{
}
public static Single getInstance()//提供公共的静态的获取对象的方法
{
return s;
}
public void test()
{
System.out.println("test Single");
}
}
Test类源码
package com;
public class Test {
public static void main(String[] args) {
Single s = Single.getInstance();//测试
s.test();
}
}