你的位置:首页 > Java教程

[Java教程]Java单例设计模式


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);      }}