Sanjana Sharma wrote:
So in what condition will the Building String arg constructor will be invoked.
Sanjana Sharma wrote:
When you say this(); , you are invoking the no arguement constructor of the Building. So just think what will happen when you call the no argument contructor of the Building from the no argument contructor of the Building itself .
Why don't you try compiling it and see the result ...
Sanjana Sharma wrote:
Can anyone explain the output : b h hn x
The String arg constructor calls its superclass constructor and that explains the b h in the output. I cannot understand the hn. What about the no arg superclass constructor?
Can anyone just run me through the above example?
Sanjana Sharma wrote:I got it. thanks a lot..
Ernest Friedman-Hill wrote:Line 19 calls line 12. Line 14 calls line 11. There's an invisible call to "super" at the beginning of House's no-argument constructor, inserted by the compiler; that goes to line 3, which prints "b". Then control returns to line 11, which prints "h". Then control returns to line 15, which prints "hn x". Then control goes back to line 20, and the program exits. The "Building" constructor with a String argument is never used.
Don't get me started about those stupid light bulbs. |