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

解决方案 »

  1.   

    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进行自增,它们值是一样的。