实例字段的继承在此特定代码中如何工作?
2022-09-01 00:14:52
class A
{
int a = 2, b = 3;
public void display()
{
int c = a + b;
System.out.println(c);
}
}
class B extends A
{
int a = 5, b = 6;
}
class Tester
{
public static void main(String arr[])
{
A x = new A();
B y = new B();
x.display();
y.display();
}
}
为什么输出显示为 5,5?而不是5,11?。该方法如何工作?y.display()