Python Practice › OOP Programs › Program 22
Five-level inheritance chain
Create 5 classes and set up multilevel inheritance among them.
Output
A B C D E ['E', 'D', 'C', 'B', 'A', 'object']
Approach
- Each class inherits from the previous one and adds one method.
Solution
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.