What is the purpose of 'this' keyword?
- 'this' keyword is used to refer current instance of an object.
- It is a non-static method and cannot be used inside main method in Java.
- It is used to invoke current class constructor.
- It can be passed as an argument in the method call.
Significance of Super keyword.
- It is used to access the methods of a parent class.
- It is a non-static method and cannot be used inside main method in Java.
- It invokes the constructor of the parent class.
- The Outer.super can be used to get current instance of an outer class and its parent in Java.
Compare 'this' vs 'super' keyword.
'this' keyword | 'super' keyword |
It represents the current instance of a class. | It represents the current instance of a parent class. |
It is used to call default constructor of the same class. | It is used to call default constructor of the parent class. |
It is used to access methods of the current class. | It is used to access methods of the base class. |
It is used for pointing the current class instance. | It is used for pointing the super class instance. |