File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

whats this mean

 
rohan yadav
Ranch Hand
Posts: 156
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the following example illustrates the problem :
 
rohan yadav
Ranch Hand
Posts: 156
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please give a meaningful subject line http://faq.javaranch.com/java/UseAMeaningfulSubjectLine
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic