swaraj gupta wrote:
I want to know from which line the super class constructor will be called.....from 11. or from 17. And if you figured out then let me know,
how did you figure out?
mohammed sanaullah wrote:
swaraj gupta wrote:
I want to know from which line the super class constructor will be called.....from 11. or from 17. And if you figured out then let me know,
how did you figure out?
The super() constructor will be called from the Overloaded constructor of ConstructorInvocation. As the default constructor of ConstructorInvocation has a call to this(int) so the compiler will not add a call to the super(), instead the overloaded constructor of ConstructorInvocation will have an implicit call to the super().
swaraj gupta wrote:can you prove that, through some code ...
mohammed sanaullah wrote:
swaraj gupta wrote:can you prove that, through some code ...
The code you provided is the proof
swaraj gupta wrote:If I would say the super class constructor has been called form line 11 then also output will be the same as what we got from line 17...that's
why i was asking...?
mohammed sanaullah wrote:
swaraj gupta wrote:If I would say the super class constructor has been called form line 11 then also output will be the same as what we got from line 17...that's
why i was asking...?
Did you try? super() or this() have to be the first statements in the constructor (if at all they are mentioned). That way you cannot have both this and super calls in the constructor. If the super() had been called from the Default constructor of the Sub class- Then After completing the execution of the super() constructor, the control would come back to the sub class's Default constructor. In that case the overloaded constructor in the Sub class would not have been called.
Harikrishna Gorrepati wrote:Dear Swaraj, This is a simple example with couple of rules. Please go through K&B. Also, we are not debating to prove it. Please do not ask like it. Your previous replies to my questions were very poor, incorrect and mislead. Please remember that you are dealing with some great people including authors. That's why I wanted to send a private message but you did not respond. Coming back to your question,
Line 12(this(7)) is calling Line 16. At the end of Line 17 has implicit call (super(), without our knowledge compiler generates one automatically) which will talk
to super class constructor which is Line 3. After completing the super class constructor (Lines 3-5), control will come back to Line# 18, execute it and return
back to Line 13 and completes the execution. K&B has very very detailed explanation on this topic. Please feel free to revert back if you are not clear at any point.
swaraj gupta wrote:Once again i am extremely thankful to you for your reply that "we cant have super() and this() in the same constructor as both of these must be the first statement of the constructor...", though i already knew this fact but actually it didn't click me...thank you very much..and please don't think that i am testing others knowledge here as Mr.Harikrishna Gorrepati said...I was having that doubt and thats why asked it...
Harikrishna Gorrepati wrote:Please click "My Profile" link on this page and choose "Yes" radio button for Allow other users to send private messages: Then, I will walk you through.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I need a new interior decorator. This tiny ad just painted every room in my house purple.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|