class model
{
private model(){}
private static model m = new model();
public static model getInstance()
{
return m;
}
private int num;
public void setNum(int num)
{
this.num = num;
}
public int getNum()
{
return num;
}
}
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
// model m = new model();
// model m2 = new model();
model m = model.getInstance();
model m2 = model.getInstance();
m.setNum(10);
m2.setNum(20);
System.out.println(m.getNum());
System.out.println(m2.getNum());
}
}
单例设计模式----体现
最新推荐文章于 2025-06-22 16:24:55 发布