Multilevel Inheritance In Java Example

Chapter: Inheritance Last Updated: 22-09-2018 08:18:37 UTC

Program:

            /* ............... START ............... */
                
class Car {
	public Car() {
		System.out.println("Class Car constructor");
	}

	public void vehicleType() {
		System.out.println("Vehicle Type: Car");
	}
}

class Audi extends Car {
	public Audi() {
		System.out.println("Class Audi");
	}

	public void brand() {
		System.out.println("Brand: Audi");
	}

	public void speed() {
		System.out.println("Max: 100Kmph");
	}
}

class AudiQ3 extends Audi {

	public AudiQ3() {
		System.out.println("Audi Model: Q3");
	}

	public void speed() {
		System.out.println("Max: 120Kmph");
	}
}

public class JavaMultiLevelInheritance {
	public static void main(String args[]) {
		Audi obj = new Audi();
		obj.vehicleType();
		obj.brand();
		obj.speed();
	}
}
                /* ............... END ............... */
        

Output

Class Car constructor
Class Audi
Vehicle Type: Car
Brand: Audi
Max: 100Kmph

Notes:

  • Multiple Inheritance refers to the concept of one class extending (Or inherits) more than one base class. The inheritance we learnt earlier had the concept of one base class or parent. The problem with “multiple inheritance” is that the derived class will have to manage the dependency on two base classes.
  • Multilevel inheritance refers to a mechanism in OO technology where one can inherit from a derived class, thereby making this derived class the base class for the new class.
  • Most of the new OO languages like Small Talk, Java, C# do not support Multiple inheritance. Multiple Inheritance is supported in C++.

Tags

Multilevel Inheritance, Java, multilevel inheritance in java using super keyword, hierarchical inheritance in java Example

Similar Programs Chapter Last Updated
Java Final Class Inheritance 02-08-2017
Java Final Method In Inheritance Inheritance 02-08-2017
Java Multilevel Hierarchical Inheritance Inheritance 01-08-2017
Java Super To Invoke Parent Class Method Inheritance 31-07-2017
Java Super To Invoke Parent Class Constructor Inheritance 30-07-2017
Static And Dynamic Binding In Java Inheritance 24-03-2017
Java Overloaded Method To Print Array Inheritance 03-09-2016
Dynamic Method Dispatch In Java Example Inheritance 19-06-2016
Abstract Class In Java Example Inheritance 20-07-2016
Method Overriding In Java Example Inheritance 20-07-2016
Method Overloading In Java Example Inheritance 20-07-2016
Inheritance And Constructors In Java Inheritance 20-07-2016
Super() In Java Example Inheritance 14-07-2016
Inheritance In Java Example Inheritance 20-07-2016

1