Howdy!
I'm going to try to point you in the direction that will help you answer the questions you have...
First,
B x = new A(); is the
polymorphism in action --
where the REFERENCE variable and the OBJECT are of different, but related types. They are related in that the OBJECT type must be either a subclass OR an implementation class of the REFERENCE type.
Polymorphically, if you invoke a method on the REFERENCE x, the actual OBJECT on the heap runs the method, so if the object has overridden the method (as the A class does with the overloaded m1(int x) method), then it is the actual OBJECT type that runs the method, rather than the REFERENCE type.
If you invoke m1(int x) on the B reference, the A object's version actually runs.
But... this is NOT the case with variables. Variables are NOT polymorphic. If you ask a B REFERENCE for its 'x' variable, you will get the B version of x, even though it is really an A object out on the heap!
Java looks only at the REFERENCE type when deciding which variable to use. It does not look to see which actual OBJECT is really being referenced.
The other quirky thing about this example (which I really like, by the way) is that even though there is only ONE object, of type A, on the heap -- the object has several 'layers'. It has its "A" parts and its "B" parts (and its Object parts, but we don't care about that now).
So the A part of the object has an 'x' variable, and the B part of the object ALSO has an 'x' variable.
But the bottom line is, variables are not polymorphic, so it is the REFERENCE type that determines whether the A or B version of 'x' is used. With methods, of course, this is completely different. Non-static methods are *always* polymorphic, so it is always the OBJECT type (regardless of the reference type) that determines which version of the overridden method will run.
(and the A constructor certainly *does* run, as does B's constructor -- in the chain, when you say 'new A()' the A constructor is invoked, which in turn invokes the B constructor, which in turn invokes the Object constructor. )
So look at the question again and see if you can make it work... (or I might have just made it even more confusing
cheers,
Kathy