File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes whats this mean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "whats this mean" Watch "whats this mean" New topic
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: 14688
    
  16

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: 774
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,
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: 537

"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: 6662
    
    5

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 - More SCJP Mocks
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: whats this mean