Python Practice › OOP Programs › Program 22

Five-level inheritance chain

EasyOOP Programs · 22 of 48

Create 5 classes and set up multilevel inheritance among them.

Advertisement
Output
A B C D E
['E', 'D', 'C', 'B', 'A', 'object']

Approach

  1. Each class inherits from the previous one and adds one method.

Solution

Python
class A:    def a(self): return "A"class B(A):    def b(self): return "B"class C(B):    def c(self): return "C"class D(C):    def d(self): return "D"class E(D):    def e(self): return "E" obj = E()print(obj.a(), obj.b(), obj.c(), obj.d(), obj.e())print([cls.__name__ for cls in E.__mro__])
Output
A B C D E
['E', 'D', 'C', 'B', 'A', 'object']

Learn the concept

New to this topic? Read the lesson, then come back.

More oop programs

← All 48 OOP Programs

Leave a Comment