Multilevel inheritance in Java


Multilevel inheritance - A class inherits properties from a class which again has inherits properties.

Example

 Live Demo

class Shape {
   public void display() {
      System.out.println("Inside display");
   }
}
class Rectangle extends Shape {
   public void area() {
      System.out.println("Inside area");
   }
}
class Cube extends Rectangle {
   public void volume() {
      System.out.println("Inside volume");
   }
}
public class Tester {
   public static void main(String[] arguments) {
      Cube cube = new Cube();
      cube.display();
      cube.area();
      cube.volume();
   }
}

Output

Inside display
Inside area
Inside volume

Updated on: 31-Oct-2023

52K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements