• Post Reply Bookmark Topic Watch Topic
  • New Topic

which one to use first between this and super?  RSS feed

 
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
Sheriff
Posts: 24217
38
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!