Java Super Keyword
Before start this discussion , you want to know about method override. For that you can read my previous blog.
https://rkavidu222.blogspot.com/2024/01/basics-of-method-overriding-in-java.html
Super Keyword:-
It is used to call parent class methods, and to access the parent class constructor. The most common use of the super keyword is to eliminate the confusion between parent classes and child classes that have methods with the same name(overriding).
1. Access Overridden Methods of the superclass
If methods with the same name are defined in both superclass and subclass, the method in the subclass overrides the method in the superclass. This is called method overriding.
The superclass and subclass can have attributes with the same name. We use the super keyword to access the attribute of the superclass.
As we know, when an object of a class is created, its default constructor is automatically called.
Comments
Post a Comment