This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Overloaded constructors can call each other using "this", and if we have several overloaded constructors that call each other using "this", then the last called constructor will call the constructor of the super class.
The following code demonstares how it happens:
Giving the output:
In Parent In Child(int x,int y) In Child(int x) In Child()
Because, when you instantiate an object of Child, its default constructor will be called, which in turn, will call the overloaded constructor with one parameters, which in turn, will call the overloaded constructor with two parameters, which finally will call the super constructor of the super class.
Now that these method calls have been placed in the call stack, the stack itself will be unwinded, giving a LIFO (Last In First Out) order, which will cause the output of "In Child(int x,int y)" first, "In Child(int x)" second, "In Child()" finally.