| 
 
| 本帖最后由 张向辉 于 2013-1-16 11:09 编辑 
 public static void main(String[] args) {
 student s=student.show();
 student s1=student.show();
 s1.setAge(6);
 s.setAge(5);
 System.out.println(s1.getAge());
 System.out.println(s.getAge());
 }
 }
 class student{
 private int age;
 public void setAge(int age){
 this.age=age;
 }
 public int getAge(){
 return age;
 }
 private student(){}
 static student stu=new student();
 public static student show(){
 return stu;
 }
 }
 
 我用单例设计模式写了一个示例
 我想问下这个结果为什么打印的是5 5 而不是6 5 s1.setAge(6)不是把值设置成6了吗那打印
 s1.getAget();结果不应该是6吗  而s.getAget()获取的值就为5 那为什么s.getAget();
 就是6呢?  谁能帮我详细分析下;
 
 | 
 |