I found another clue in the assertion spec, section Semantics. �It is possible, though generally not desirable, to execute methods or constructors prior to initialization. This can happen when a class hierarchy contains a circularity in its static initialization...�
They also give an example, but not one that executes a constructor before a static initializer.
If the inherited method uses the overriden method. Should not the inherited method use the overriden field?
If the inherited method uses the overriden method
"Overriding a variable" is called "shadowing" the variable.
The virtual machine uses the overriding method, not the overridden method.
In both cases, the virtual machine uses the overridden method and the shadowing variable within that overridden method.
This idea takes a while to develop roots. The more examples I see, the more I understand.
I think I get it
Yes. The compiler determines which declaration of a variable to use.
The *compiler* always works out which variable (based on the class).
Yes. There are compile-time steps and run-time steps to choose an instance method.
Runtime decision is only on instance methods (based on the underlying object).
Yes. When an object is created, memory is allocated for all the instance variables declared in the class and all the instance variables declared in each superclass, including all the instance variables that may be hidden.
the subclass in fact contains 2 identical variables,
When compiling class A, the compiler does not consider the declaration in the subclass B. At compile-time, the declaration of v in A is not hidden from the method print() in A.
just you can't access the hidden one.
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earthhttps://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter