Hi, the output for this code is "b h hn x". I expected the output to be "b bn h hn x". I understand that the superclass constructor will be invoked first. I expected that String constructor will also be invoked.
Stuart James wrote:This() calls the default constructor on the sub class. . . .
Not quite. It calls the no-arguments constructor in the same class (House). Because you have defined a constructor, there is no default constructor. Since there is no explicit super(...) call in that no-arguments constructor, the JVM calls the no-arguments constructor in the superclass.
Thank you all...
Jesper thank you for the detailed explanation. Since the superclass constructors are invoked first, I thought the superclass constructor with a string argument will be invoked when Horse is instantiated with a string argument. Now it sounds silly.