• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

this() and super()

 
T George
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have been roaming around in here for quite some time and it is always very helpful. However this is my first post.
Now straight to business

I know(i think in know) that you can't put super() in a constructor if you have put the this() in the constructor but is it possible to put this() after a super() in a constructor.
In other words does this() also has to be on the first line in the constructor?

Thank you in advance
Thomas
 
Cm Ananth
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.. this() and super() needs to be the first statement..
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34851
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas,
Yes. Since the constructor creates an object, only one may be called. If you want to call both this() and super(), you can have the other constructor do so for you. A common technique is:

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34851
369
Eclipse IDE Java VI Editor
 
T George
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ananth and Jeanne for the help.
Appreciate it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic