Object Oriented Programming - JAVA - Method Overriding - Super keyword

 

Object Oriented Programming - JAVA 👽

Do you know about method overriding? 

We can't run super class method in method overriding with out special keyword "Super".
Super keyword is used to call the constructor of parent class from child class and refer to the things in  the super class.

Ex :
   class Father{
        Father() {
             sout ("Father of a child");
        }
   } 
   class Son extends Father{
        Son() {
            Super();
        }
   } 
   class Test{
        psvm {
             Son s = new Son();
        }
   }

The  'S' in the Super keyword is always capital.
We can access the super class's constructor, methods & variables with the Super keyword.
  • Super () ; 
            Used to call constructor of parent class.
  • Super.methodName () ; 
            Used to call mathods of parent class.
  • Super.variableName ;
            Used to call variables of parent class.

Let's meet in the next blog to discuss about "How to inherit classes" .

Comments

Popular posts from this blog

Application Programming Interface (API)

Sorting Algorithms - JAVA👽

Object Oriented Programming - JAVA- class boundary, variable types, modifiers, java main method