In the code below, the instance variable called "x" inside subclass "B" hides the instance variable also called "x" inside the parent superclass "A".
public class A {
public int x;
}
public class B extends A {
public int x;
}
In the code below, why does println(z.x) display the value of zero? Thanks.
A a = new A();
B b = new B();
a.x = 1;
b.x = 2;
A z = b;
System.out.println(z.x); // Prints 0, but why?