当前位置: 代码迷 >> Java相关 >> 请教各位一个问题?
  详细解决方案

请教各位一个问题?

热度:64   发布时间:2007-11-07 21:47:56.0
请教各位一个问题?
public class GroupThree{
private static int count;
private String name;
public class Student{
private int count;
private String name;
public void Output(int count){
count++;
this.count++;
GroupThree.count++; //有疑问的语句
GroupThree.this.count++;//有疑问的语句
System.out.println(count+" "+this.count+" "+GroupThree.count+" "+GroupThree.this.count++);有疑问的语句
}
}
public Student aStu(){
return new Student();
}
public static void main(String[]args){
GroupThree g3=new GroupThree();
g3.count=10;
GroupThree.Student s1=g3.aStu();
s1.Output(5);
}
}
输出结果是:6 1 12 12
问题一:
为什么GroupThree.count;和GroupThree.this.count++;无论注释哪一句,GroupThree.count和GroupThree.this.count++的结果都一样.
问题二:将GroupThree.this.count++的++去掉,输出的结果和去掉之前一样.

[此贴子已经被作者于2007-11-7 21:49:03编辑过]


----------------解决方案--------------------------------------------------------
难道就没有一个人能看懂这个程序吗?
----------------解决方案--------------------------------------------------------
1,因为GroupThree里面的count是静态的,你用成员和用类访问效果是一样的,并且推荐用类来访问它
2,X++是先算完再做+1的运算,所以最后一个++的动作当然有和没有一样了.

----------------解决方案--------------------------------------------------------
回复:(千里冰封)1,因为GroupThree里面的count是静态...
谢谢啦.我明白了.
----------------解决方案--------------------------------------------------------
  相关解决方案