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

来源:互联网 发布:苹果cpu测试软件 编辑:程序博客网 时间:2024/05/16 07:32
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);// 20System.out.println(this.num);// 20System.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值的呢?不明白为什么?
原创粉丝点击