*
The moose likes Beginning Java and the fly likes which one to use first between this and super? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "which one to use first between this and super?" Watch "which one to use first between this and super?" New topic
Author

which one to use first between this and super?

Sonu Nigam
Greenhorn

Joined: Jun 22, 2008
Posts: 2
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

Joined: Jul 11, 2001
Posts: 14112
You can't call both a super- and this-constructor in one constructor. It's simply not allowed.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
jQuery in Action, 2nd edition
 
subject: which one to use first between this and super?