Author | Topic: Confused help me!! |
sree ranch hand |
posted March 29, 2000 04:14 PM
Hi Guys, I am confused with the follwing code. code: The output is Child.test() Base construtor called Child.test(). Why not? Thanks. [This message has been edited by maha anna (edited March 29, 2000).]
|
maha anna bartender |
posted March 29, 2000 09:54 PM
sree, I purposly waited for someone to initiate. So here is some help. I am using a general format for explaining this. Step1 : Step2 So the foll constructor is called.
which is same as
Step 4 Step 5 step 6 I hope this helps. For simplicity I created more steps. But when you understand the concept, just looking itself you can follow the execution flow.
|
Umesh ranch hand |
posted March 29, 2000 10:46 PM
Anna, What is the compiler rule to provide super() in the subclass constructor ?
[This message has been edited by Umesh (edited March 29, 2000).]
|
maha anna bartender |
posted March 30, 2000 12:45 AM
Umesh, All constructors in any subclass will have the super() statement as their first statement by default. Unless.... ... when you put explicitly either this(..) or super(...) as first statement of any subclass constructor, then the automatic insertion of super() statement is NOT DONE. Since either ONLY ONE statement of this(...) or super(..) can be as the first statement of any constructor. Also note that the ansestor of all types in Jave, the Object class doesn't have a super class. Follow the foll. code.
Cut and paste this code as a Java appln and test the concepts. I am writing this well past midnight. I might have missed some. regds maha anna [This message has been edited by maha anna (edited March 30, 2000).]
|
sree ranch hand |
posted March 30, 2000 06:04 AM
Thanks maha.
|
Umesh ranch hand |
posted March 30, 2000 08:24 PM
Wonderful Anna.....its set in my mind.....thanls a lot.
|
| | |