java基础语法(二)--单列模式

复制代码
/**
 * 功能:单列模式
 * @author Administrator
 *
 */
public class SingletonTest
{
    public static void main(String[] args)
    {
        Singleton test1 = Singleton.getInstance();
        Singleton test2 = Singleton.getInstance();
        
        System.out.println(test1 == test2);
    }
}


class Singleton
{
    private static Singleton singleton = new Singleton();
    
    private Singleton()
    {    }
    
    public static Singleton getInstance()
    {        
        return singleton;        
    }
}
posted @ 2014-04-11 11:53  JAVA之迷  阅读(127)  评论(0编辑  收藏  举报