File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
I agree. Here's the link:
subject: i dont understand super()
It's not a secret anymore!