Loading notes...
Loading notes...
B.Tech • Chapter 9
B.Tech level module on Advanced OOP.
Inheritance allows a class to inherit attributes and methods from another class. Python supports Multiple Inheritance, which requires a specific algorithm to resolve method calls.
Advanced Engineering Concepts
Method Resolution Order (MRO) dictates how Python searches for base classes during method calls in a multiple inheritance scenario. Python uses the C3 Linearization algorithm to determine the MRO. Polymorphism allows methods to be overridden in child classes, ensuring that the correct method is called based on the object's actual class at runtime. The 'super()' function dynamically accesses methods of the parent class following the MRO.
Code Implementation
class A:
def process(self): print("A")
class B(A):
def process(self):
print("B")
super().process()
class C(A):
def process(self):
print("C")
super().process()
# Multiple Inheritance
class D(B, C):
def process(self):
print("D")
super().process()
obj = D()
obj.process()
print(D.mro()) # D -> B -> C -> A -> object