The code above gives the output: Creating an object of SubclassB. Constructor in SuperclassA value: 0 Constructor in SubclassB value: 800 superValue: 0
MY QUESTION: I thought that member variables are initialized at class load time which is before the call to the constructors. The code above, seen from output, shows that value was not initialized to 800 before this.doValue() of SuperClassA was called. How is that so?
Edited by Corey McGlone: Added CODE Tags [ June 22, 2004: Message edited by: Corey McGlone ]
Member variables are initialized to 0 when the class is initially instantiated. It won't be set to 800 until the proper instance member initializer is executed. If you look at your other post (where I cite the steps the JLS lays out), you'll notice that the instance member initializers of the subclass don't execute until after the constructor of the superclass executes completely.
Also, it's important to note that the method invocation in your superclass actually invokes the method in the subclass because the method is overridden. The method doValue in the superclass is actually never executed.