
Java
Example:
public class A {
public String getName(){
return "Vijay";
}
}
public class B extends A {
public int getAge() {
return 24;
}
}
public class C extends B {
public String getAddress(){
return "Utter Pradesh,India";
}
}
public class D extends C {
public void print {
System.out.println(getName());
System.out.println(getAge());
System.out.println(getAddress());
}
}
This method would print the following in the console:
Vijay
24
Pradesh,INDIA
Here in class D you are calling methods that are available inside classes A, B & C. Though D extends only class C, it would in turn inherit the properties of the classes extended by C and its parents.
This is multi level inheritance.
Copyright © 2026 eLLeNow.com All Rights Reserved.