Java单例设计模式

12/12/2015来源:Java教程人气:1246

class Singleton{
    PRivate static Singleton obj = new Singleton();
    private Singleton(){}
    public static Singleton getInstance(){
        return obj;
    }
    public String toString(){
        return "Hello world!";
    }
}


public class SingletonDemo {

    public static void main(String[] args) {
        Singleton o = Singleton.getInstance();
        System.out.println(o);        
    }
}