Java Program for hierarchical inheritance using super keyword
In this program, You will learn how to implement hierarchical inheritance using super keyword in java.
void msg() {
super.msg();
}
Example: How to implement hierarchical inheritance using super keyword in java.
class A {
void msg() {
System.out.println("A is called here");
}
}
class B extends A {
void msg() {
super.msg();
System.out.println("B is called here");
}
}
class Main extends A {
void msg() {
super.msg();
System.out.println("Main is called here");
}
public static void main(String args[]) {
B obj1 = new B();
obj1.msg();
Main obj2 = new Main();
obj2.msg();
}
}
Output:
A is called here
B is called here
A is called here
Main is called here