The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
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.
SCJP2. Please Indent your code using UBB Code
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
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.
Don't get me started about those stupid light bulbs. |