Multi Level Inheritance
class Class_1 {
int age = 30;
String name = "smith";
public void display_1() {
System.out.println("age: " + age);
System.out.println("name: " + name);
}
}
class Class_2 extends Class_1 { /* Now Class_2 contains all the public members of Class_1 through
Simple Inheritance */
public void display_2() {
System.out.println("Inside Class_2");
}
}
public class MultiLevel extends Class_2 { /*Now the class MultiLevel contains
all the public members of the Class_2 through MultiLevel Inheriance */
public static void main(String[] args) {
MultiLevel ml = new MultiLevel();
ml.display_1();
ml.display_2();
}
}
Output:
age: 30
name: smith
Inside Class_2