0% found this document useful (0 votes)
9 views

Multilevel Inheritance Example

Multilevel inheritance

Uploaded by

divyamc786
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Multilevel Inheritance Example

Multilevel inheritance

Uploaded by

divyamc786
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Multilevel Inheritance Example

In this example we have three classes – Car, Maruti and Maruti800. We have done a setup – class
Maruti extends Car and class Maruti800 extends Maruti. With the help of this Multilevel hierarchy
setup our Maruti800 class is able to use the methods of both the classes (Car and Maruti).

class Car{

public Car()

System.out.println("Class Car");

public void vehicleType()

System.out.println("Vehicle Type: Car");

class Maruti extends Car{

public Maruti()

System.out.println("Class Maruti");

public void brand()

System.out.println("Brand: Maruti");

public void speed()

System.out.println("Max: 90Kmph");

public class Maruti800 extends Maruti{

public Maruti800()

{
System.out.println("Maruti Model: 800");

public void speed()

System.out.println("Max: 80Kmph");

public static void main(String args[])

Maruti800 obj=new Maruti800();

obj.vehicleType();

obj.brand();

obj.speed();

Output:

Class Car

Class Maruti

Maruti Model: 800

Vehicle Type: Car

Brand: Maruti

Max: 80Kmph

You might also like