What is the difference between super() and this()?
What is the difference between super() and this()?
super() is used to call super class constructor, whereas this() used to call constructors in the same class, means to call parameterized constructors.
The keyword this() used to invoke a constructor of the same class super() can be used to invoke a super class constructor this is the main difference of the super and this keyword.
this() can be used to invoke a constructor of the same class
super() can be used to invoke a super class constructor
super() is used to call super class constructor, whereas this() used to call constructors in the same class, means to call parameterized constructors.
1.Super is a keyword used to call constructor of the immediate parent class or access its properties . It is used to basically initialize the parent class. Super statement should always be first statement.
2.This keyword is used to access its own instance properties (since it can only access instance variables and methods). We can use this keyword anywhere we want as long as it does access some instance properties and used by object.
Bookmarks