Java Multilevel Hierarchical Inheritance

Chapter: Inheritance Last Updated: 01-08-2017 15:44:38 UTC

Program:

            /* ............... START ............... */
                
class A {
	public void methodA() {
		System.out.println("method of Class A");
	}
}

class B extends A {
	public void methodB() {
		System.out.println("method of Class B");
	}
}

class C extends A {
	public void methodC() {
		System.out.println("method of Class C");
	}
}

class D extends A {
	public void methodD() {
		System.out.println("method of Class D");
	}
}

public class JavaMultilevelHierarchy {

	public void methodB() {
		System.out.println("method of Class B");
	}

	public static void main(String args[]) {
		B obj1 = new B();
		C obj2 = new C();
		D obj3 = new D();
		obj1.methodA();
		obj2.methodA();
		obj3.methodA();
	}
}

                /* ............... END ............... */
        

Output

method of Class A
method of Class A
method of Class A

Notes:

  • In simple inheritance a subclass or derived class derives the properties from its parent class, but in multilevel inheritance a subclass is derived from a derived class. One class inherits only single class. Therefore, in multilevel inheritance, every time ladder increases by one. The lower most class will have the properties of all the super classes’.

Tags

Multilevel Hierarchical Inheritance, Java, Inheritance

Similar Programs Chapter Last Updated
Java Final Class Inheritance 02-08-2017
Java Final Method In Inheritance Inheritance 02-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
Multilevel Inheritance In Java Example Inheritance 21-06-2017
Super() In Java Example Inheritance 14-07-2016
Inheritance In Java Example Inheritance 20-07-2016

1