Ste Davies wrote:Hi All, I understood that if you put the keyword 'this' in a constructor the compiler doesn't insert super().
But this code still calls Alpha even though it has a 'this' in the Beta constructor
Ste, Can you tell us the reference where you encountered this fact? Usually super has to be the first statement in the constructor (if explicitly mentioned). Compiler automatically inserts a call to super() [Default super constructor) and your Super class must provide a default constructor (if at all you have other overloaded constructors).
when we create a sub class object, it calls appropriate constructor of the sub class which in turn calls the default constructor of superclass (though we can change this behavior by using super()) Now the super class constructor will be executed first then the sub class's constructor.
So, the order of invocation is always opposite to the order of execution.
I think this is enough.
And talking about your "this", it is merely representing the current instance of Beta();.....whatever you understood is wrong..!! tc
posted 8 years ago
Kevin: So its this() which excludes super() not this.something ?
Mohammed: The reference was Sierra & Bates, chapter2, P160: "The compiler will add a call to super() unless you have already put in a call
to this() or super()."