首页 > 学院 > 开发设计 > 正文

Java单例设计模式

2019-11-14 14:51:38
字体:
来源:转载
供稿:网友
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);            }}

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表