The variable x in the class Child hides the variable x in the class Base. (Base.x is still there, we just can't see it unless we use the super keyword.)
You know that there is an implicit call to the superclass constructor. But realize that when this superclass call is made the varlable Child.x has not yet been initialized. Until we return from the superclass constructor, its value will remain the default value of zero. Only then will the initialization in the subclass occur.
The subclass version of show is called because even though the superclass constructor is called, it is a Child instance that has been created, and it is that implementation that can be executed.
The base class constructor is called from the implicitly placed super() in the child's constructor. I hope you understand this.
When the super class constructor, the object in creation is the child class object. So in the super class constructor, when you try to call an overridden method, the method present in the actual object will be called.
Try marking the super class method as either final or private and note the difference.
We had a recent discussion on this topic. I will get that thread for you.
I thought a constructor is not able to access instance methods unless its super constructor has completed. This does not appear to be the case here.
posted 6 years ago
The super constructor is first run and it's the code in the super constructor that calls the child's instance method. Code in child's constructor runs only after the call to super() finishes. Your thought was correct Ziggy.