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.


2. Access Attributes of the Superclass
    The superclass and subclass can have attributes with the same name. We use the super keyword to access the attribute of the superclass.


3. Use of super() to access superclass constructor
    As we know, when an object of a class is created, its default constructor is automatically called.



    super
keyword is a powerful tool in Java's object-oriented programming paradigm, providing a means to navigate and interact with the hierarchy of classes, facilitating code organization, readability, and reuse.

 


Comments

Popular posts from this blog

අද අපි කතා කරමු Data collections ගැන

Understanding and Mastering Coding Errors

OOP key points