Home Tutorials Python OOP Concepts Hierarchical Inheritance
Hierarchical Inheritance

Hierarchical Inheritance


16. Hierarchical Inheritance

Hierarchical inheritance means multiple child classes inherit from the same parent class. This is useful when several classes share common behavior.

Syntax

class B(A):
    pass

class C(A):
    pass

Example

class Shape:
    def info(self):
        print("This is a shape")

class Circle(Shape):
    pass

class Square(Shape):
    pass

c = Circle()
s = Square()
c.info()
s.info()

Output

This is a shape
This is a shape
Example

🏋️ Test Yourself With Exercises

Take our quiz on Hierarchical Inheritance to test your knowledge.

Browse Quizzes »