Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which one to use first between this and super?

 
Sonu Nigam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if in a subclass we want superclass constructor to be accessed and i want to use both this and super keyword and both are written just after the constructor defined then in above case which one will be written first?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't call both a super- and this-constructor in one constructor. It's simply not allowed.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only use one of the two. If you use "this", then another constructor will be called in the same class; if that constructor uses "this", then a third constructor will be called, etc. Eventually, you'll get to a constructor that doesn't use "this", and in that constructor, "super" can appear.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic