Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use of super() in non inherited class

 
Rajesh Veluchamy
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the below code there is a super() in class which is not a child class(there is no extends)

Then what is the use of that "super();"


 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then what is the use of that "super();"

Think twice Don't Java classes all extend the same class ?
I don't find the super() particularly useful here though. If you don't write it, the compiler will implicitly put it for you anyway.

The Java Language Specification
8.8.7 Constructor Body
The first statement of a constructor body may be an explicit invocation of another constructor of the same class or of the direct superclass. If a constructor body does not begin with an explicit constructor invocation and the constructor being declared is not part of the primordial class Object, then the constructor body is implicitly assumed by the compiler to begin with a superclass constructor invocation "super();", an invocation of the constructor of its direct superclass that takes no arguments.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As already said above, "that super()" may not be useful, and just to add on,
all Java classes are CHILDREN of java.lang.Object.

Hope this helps
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit Ghorpade:
all Java classes are CHILDREN of java.lang.Object.


that's what I thought to point you regarding to the concept super class,

here is tutorial for Object as a Superclass and Using the Keyword super provided by Sun.

These might help you in that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic