Super keyword in Java
Super keyword in Java
It’s a reference variable that is used to be referring immediate parent class objects. This concepts came from inheritance.
Super keyword used in the below forms
- Super with Variables
- Super with Methods
- Super with Constructors
Super with Variables:
If parent and child class has same variable then this will be achieve using super keyword.
Example:
Output:
Super with Methods:
If parent and child class has same methods then this will be achieve using super keyword. suppose the below same method in both classes then it will be call as.
Example:
show(); // child class super.show(); // Parent Class
Super with Constructors:
Using super keyword we can call parent class constructor also and it can be default and parameterized.
Example:
Output:
Are you Interested in Java Course? – Click Here !