Java Program to Implement Multi-Level Inheritance

You are currently viewing Java Program to Implement Multi-Level Inheritance

Java program to implement multi-level inheritance

// Java program to implement 
// multi-level inheritance

class Base {
  void BaseMethod() {
    System.out.println("Base method called.");
  }
}

class Derived1 extends Base {
  void Derived1Method() {
    System.out.println("Derived1 method called.");
  }
}

class Derived2 extends Derived1 {
  void Derived2Method() {
    System.out.println("Derived2 method called.");
  }
}

public class Main {
  public static void main(String[] args) {
    Derived2 obj = new Derived2();
    obj.BaseMethod();
    obj.Derived1Method();
    obj.Derived2Method();
  }
}

Output

Base method called.
Derived1 method called.
Derived2 method called.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply