public class SingleDemo
{
public static void main(String[] args)
{
Test t1 = Test.getInstance();
Test t2 = Test.getInstance();
t1.setNum(10);
t2.setNum(20);
System.out.println(t1.getNum());
System.out.println(t2.getNum());
}
}
class Test
{
private int num;
private static Test t = new Test();
private Test(){}
public static Test getInstance()
{
return t;
}
public void setNum(int num)
{
this.num = num;
}
public int getNum()
{
return num;
}
}
运行结果都是20,记得毕老师讲过,再翻着看找不到这个知识点了。为什么都是20啊?表面上看,不应该是10,20么?{:3_65:}
|
|