Multilevel inheritance in Java

JavaJava Programming Java 8

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
raja
Published on 02-Feb-2018 08:28:07
Advertisements