您的位置:首页 > 编程语言 > Java开发

Java中在从父类中继承的成员变量在子类改变,怎么父类(super.num)的成员也一起改变?

2013-08-18 10:35 656 查看
class Father {
protected int num = 10;

public void setNum(int num) {
this.num = num;
}
public int getNum() {
return num;
}
}
class Child extends Father {
public void show() {
System.out.println(num);			// 20
System.out.println(this.num);		// 20
System.out.println(super.num);		// 20
}
}

public class TestExtends01 {
public static void main(String[] args) {
Child child = new Child();
//child.show();
child.setNum(20);
child.show();
}
}
为什么super.num也变成20值的呢?不明白为什么?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐