Can any one please tell me what is the difference between super() call and this() call in java constructors?
-
A google-able question . super() is for calling superclass' constructor . this() is current class – Caffeinated Feb 25 '14 at 15:57
-
`this` refers to constructor of (guess what...) current (this) class. `super` refers to constructor of superclass. – Pshemo Feb 25 '14 at 15:57
-
https://stackoverflow.com/help/how-to-ask – Kushan Randima Sep 18 '17 at 03:58
7 Answers
this()
calls another constructor for the same class. In this case the 0 argument one.
super()
calls the constructor for the super class.

- 5,641
- 1
- 23
- 35
super() calls no-argument constructor from superclass and this() calls no-arg constructor from the current class.

- 2,130
- 9
- 16
super()
calls the parent constructor of the class and this()
calls the constructor defined within the class.
//Example of super()
class parent
{
parent()
{
}
}
class child()
{
child()
{
super(); //Go to parent class constructor
}
}
//Example of this
class test
{
test()
{
this("a"); //go to test one argument constructor within the test class
}
test(String a)
{
}
}

- 589
- 1
- 4
- 16

- 691
- 7
- 17
super() refers to the base/parent class. Can be used in constructor to invoke parent constructor but must be done in the declaration of the constructor.

- 12,971
- 1
- 25
- 32
It means you are delegating part of the object construction to another constructor, being super()
a constructor defined in a superclass and this()
a constructor defined in the same class.

- 1,180
- 2
- 12
- 27
The super()
is for calling superclass' constructor . this()
refers to the current class .
Here are good SO-links.

- 1
- 1

- 11,982
- 40
- 122
- 216