martin
The first thing that happens when a costructor is called is if there is no call to a superclass constructor and no call to a different constructor of the same class (using this( )) then an implicit call is made to the default superclass constructor.
For the exact details check out the
JLS section 12.5.
So basically the steps are:
1 -- executing the line 'Base b = new Derived();' causes control to go to the constructor for the Derived class.
2 -- Becasue there is no 'this' call and no call to 'super' the Base class default constructor is called.
3 -- in the Base constructor the method addValue is called, because the underlying object is a Derived object it calls the addValue method of the Derived class.
4 -- The addValue method of the Derived class adds 20 to the value of the value variable. Then it returns.
5 -- After the addValue method returns the Base constructor returns to the Derived constructor and start executing at the 1st line.
6 -- The 1st line of the Derived constructor is another call to addValue - again it is the Derived classes addValue method that is called.
7 -- Another 20 is added to the value variable.
8 -- The Derived constructor is done and a Derived object is returned and stored in the variable 'b'.
Hope that helps you out.