Java - 'super' keyword in java with example
The super keyword in Java is a reference variable that is used to refer to the immediate parent class object. Whenever you create the instance of a subclass, an instance of the parent class is created implicitly which is referred to by a super reference variable. The use of a super keywords, To access the data members of parent class when both parent and child class have a member with the same name To explicitly call the no-arg and parameterized constructor of the parent class To access the method of parent class when the child class has overridden that method. 1. To access the data members of parent class when both parent and child class have a member with the same name We can use the super keyword to access the data member or field of the parent class. It is used if parent class and child class have the same fields. class Animal { String action = "Animal sleeping" ; } public class Lion extends Animal { String action = "Lion roaring" ;