内部类值的输出疑问

StruggleCenter 2010-09-14 11:45:21
public class Group{
private static int coun;
private String name;
public class Student{
private int count;
private String name;
public void output(int count){
count++;
this.count++;
Group.coun++;
Group.this.coun++;
System.out.println(this);
System.out.println(count+" "+this.count+" "+Group.coun+" "+Group.this.coun++);
}

}
public static void main(String[] args){
Group g=new Group();
g.coun=10;
Group.Student s1=g.new Student();
s1.output(5);
}
}

输出结果:6 1 12 12
...全文
65 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuxianyue 2010-09-15
  • 打赏
  • 举报
回复
System.out.println(count+" "+this.count+" "+Group.coun+" "+Group.this.coun++)
count是方法参数,自增1,为6;
this.count为内部类对象Student的成员变量,默认值为0,自增1,为1;
Group.coun为外部类Group的静态字段,在main函数初始化10,但由于经过Group.coun++;
Group.this.coun++;两个自增,值变为12,Group.this.coun++和Group.coun++都是对
Group的静态字段coun进行自增,它们值是一样的。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧