This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes i dont understand super() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "i dont understand super()" Watch "i dont understand super()" New topic

i dont understand super()

neil harper

Joined: Oct 30, 2010
Posts: 14
super() calls the superclass constructor correct? in what situation would this be beneficial?
Martin Caminoa

Joined: Oct 25, 2010
Posts: 5
It's utile to call the constructor method from superclass because constructors are not inherited
marc weber

Joined: Aug 31, 2004
Posts: 11343

See Java Tutorials - Using the Keyword super for details and examples.

Note that "if a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass." So if the no-argument constructor is what you want, there isn't a need to insert "super()" without arguments.

On the other hand, if you want to invoke a superclass constructor with arguments, then you must explicitly call super(args...) from the subclass constructor.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
jQuery in Action, 2nd edition
subject: i dont understand super()