Object Oriented Programming - JAVA - Method Overriding - Super keyword
Object Oriented Programming - JAVA 👽
Do you know about method overriding?
Method Overriding Blog : https://miyurangika1223.blogspot.com/2024/02/object-oriented-programming-java-method.html
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.
Comments
Post a Comment