public class PolymorphismTest {public void show() {
A a = new B();
B b = new B();
a.show();
b.show();
System.out.println("a.a: " + a.a);
System.out.println("b.a: " + b.a);
}
public class A {
public int a = 5;
public void show() {
System.out.println("A show");
}
}
public class B extends A {
public int a = 6;
public void show() {
System.out.println("B show");
}
}}show()函数执行实验结果:B showB showa.a: 5b.a: 6为什么这里a.a的值是5而不是6呢?
添加回答
举报
0/150
提交
取消