Demo of MRO resolution with multiple inheritance
This commit is contained in:
parent
1da4f731a5
commit
bac5abb664
20
mro_resolution_example.py
Normal file
20
mro_resolution_example.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Example to demonstrate Method Resolution Order (MRO) in Python
|
||||
|
||||
class A:
|
||||
def greet(self):
|
||||
print("Hello from A")
|
||||
|
||||
class B(A):
|
||||
def greet(self):
|
||||
print("Hello from B")
|
||||
|
||||
class C(A):
|
||||
def greet(self):
|
||||
print("Hello from C")
|
||||
|
||||
class D(C, B):
|
||||
pass
|
||||
|
||||
d = D()
|
||||
d.greet() # Hello from C (based on MRO)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user