📘 Lesson · Lesson 87
Multiple Inheritance & MRO
Multiple Inheritance
💡 At a Glance
Unlike Java, Python allows a class to inherit from multiple parents. The MRO (Method Resolution Order) decides which parent's method runs first.
Example
Python
class A:
def show(self): print("A")
class B(A):
def show(self): print("B")
class C(A):
def show(self): print("C")
class D(B, C): # multiple inheritance
pass
d = D()
d.show() # follows MRO: D -> B -> C -> A
print(D.__mro__)B
(<class 'D'>, <class 'B'>, <class 'C'>, <class 'A'>, <class 'object'>)
Summary
- Python allows multiple inheritance (D from B and C).
- MRO decides method order: check with
ClassName.__mro__.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.