← Back to Core Java Course | Chapter 8: Inheritance | Lesson 3 of 7

Java Multilevel Inheritance

Multilevel inheritance is a chain of parents, like grandparent, parent, and child, where each level passes things down. The youngest gets features from all of them.
Syntax
java
class Grandparent { }
class Parent extends Grandparent { }
class Child extends Parent { }

What is Multilevel Inheritance?

Multilevel inheritance chains classes together — C extends B, and B extends A — so C ends up inheriting from both its direct parent B and, transitively, from B's own parent A, forming a multi-tier hierarchy.

Example: What is Multilevel Inheritance?

java
class A {}
class B extends A {}
class C extends B {} // chain: C -> B -> A
public class Main {
	public static void main(String[] args) {
		C c = new C();
		System.out.println(c instanceof A);
	}
}

Method Overriding in Multilevel Chains

Any class in the chain can override a method it inherited, and that override applies to it and everything below it in the chain, letting each tier customize behavior progressively as you move down the hierarchy.

Example: Method Overriding in Multilevel Chains

java
class A {
	void show() { System.out.println("A"); }
}
class B extends A {
	@Override
	void show() { System.out.println("B"); }
}
class C extends B {
}
public class Main {
	public static void main(String[] args) {
		new C().show(); // uses B's override
	}
}

Constructor Chaining

Constructors run in order from the topmost ancestor down to the class actually being instantiated — A's constructor runs first, then B's, then C's — ensuring every level of the hierarchy gets to initialize its own portion of the object's state before the next level begins.

Example: Constructor Chaining

java
// Define the class A
class A {
	A() { System.out.println("A constructor"); }
}
// Define the class B
class B extends A {
	B() { System.out.println("B constructor"); }
}
class C extends B {
	C() { System.out.println("C constructor"); }
}
public class Main {
	// Program entry point: the JVM starts running here
	public static void main(String[] args) {
		new C();
	}
}

The super Keyword in Chains

super inside class C only reaches its immediate parent B, not grandparent A directly — if C needs something from A specifically, it has to go through B (assuming B exposes it), since super doesn't skip levels.

Example: The super Keyword in Chains

java
class A {
	void show() { System.out.println("A"); }
}
class B extends A {
	void showB() { super.show(); } // reaches only immediate parent A
}
class C extends B {
}
public class Main {
	public static void main(String[] args) {
		new C().showB();
	}
}

Instanceof in Multilevel Chains

An object created from the bottom class in the chain is considered an instance of every class above it, so instanceof checks against A, B, or C would all return true for that single object.

Example: Instanceof in Multilevel Chains

java
// Define the class A
class A {}
// Define the class B
class B extends A {}
class C extends B {}
public class Main {
	// Program entry point: the JVM starts running here
	public static void main(String[] args) {
		// Create a new C object and store it in c
		C c = new C();
		// Print a line to the console
		System.out.println(c instanceof A);
		// Print a line to the console
		System.out.println(c instanceof B);
		System.out.println(c instanceof C);
	}
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Forgetting that constructors run from the top parent down to the child.
  2. Forgetting that a call to super.method() runs only the direct parent version, so grandparent behaviour is skipped unless the parent calls it.
  3. Making chains so deep that a change in the base class breaks many subclasses.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.