| Author |
whats this mean
|
rohan yadav
Ranch Hand
Joined: Oct 13, 2009
Posts: 156
|
|
In k&b book of scjp5 page no130
there is one line saying "You cannot make call to an instance method or access instance variable until after the super constructor runs"
whats that mean??
Can anyone explain with example?
Thanks in advance!!!
|
Sage of The Monstrous Toad of Mount Myoboku
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
I think that the following example illustrates the problem :
|
[My Blog]
All roads lead to JavaRanch
|
 |
rohan yadav
Ranch Hand
Joined: Oct 13, 2009
Posts: 156
|
|
Thanks for replaying Christophe Verré.I got the concept now, i was thinking that once you have called super() method you cant call the instance method.
But i got that super has to call first.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
please give a meaningful subject line http://faq.javaranch.com/java/UseAMeaningfulSubjectLine
|
 |
Prithvi Sehgal
Ranch Hand
Joined: Oct 13, 2009
Posts: 771
|
|
super() should always be the first line in the constructor. If your super-class has a no-arg constructor, you
don't need to put super() yourself, compiler will insert it for you. Look below
Please do use meaningful subject lines, so that you can get the response quickly.
HTH,
|
Prithvi/Beenish,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
|
 |
Nitish Bangera
Ranch Hand
Joined: Jul 15, 2009
Posts: 536
|
|
"You cannot make call to an instance method or access instance variable until after the super constructor runs"
THis is why if an explicit call for super() is put, it should be put as the first line in the constructor.
|
[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6592
|
|
Hi rohan,
Welcome to javaranch. When you post here again, make sure that you provide a subject line that describes your problem. That way more users will reply to your question.
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Vlado Zajac
Ranch Hand
Joined: Aug 03, 2004
Posts: 244
|
|
It means not only that super(...) needs to be first statement in constructor but also that you cannot use instance variables or methods in the super(...) call.
This is forbidden:
|
 |
 |
|
|
subject: whats this mean
|
|
|