Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i dont understand super()

 
neil harper
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
super() calls the superclass constructor correct? in what situation would this be beneficial?
 
Martin Caminoa
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's utile to call the constructor method from superclass because constructors are not inherited
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic