private int id;
private String name;
public static Demo01 demo01=new Demo01();
// 构造函数私有化,就不能创建其他对象了
private Demo01(){
}
public static Demo01 get(){
return demo01;
}
public void put(){
System.out.println("hhhhhhhh!!");
}
一个简单的单例模式代码
最新推荐文章于 2022-10-18 23:53:19 发布