What is super ?
The super keyword in Java is a reference variable which is used to refer immediate parent class object.
Whenever you create the instance of subclass, an instance of parent class is created implicitly which is referred by super reference variable
why we use super keyword ?
To access parent class variable
If child and parent have same variable names,we can use super variable name to access the parent's variable
To access parent's class method
If child overrides a parent method we can call the parent's method using super name ().
when super is used ?
Inside a method (to call parent's variable or parent's method )
When there is overriding or same variable names parent and child
Top comments (0)