Method Overriding and super()
Override parent methods and call them with super().
Introduction
Method overriding lets child classes customize inherited behavior. super() lets you call the original implementation.
Overriding Basics
Define the same method name in the child class to replace the parent's version for all instances of the child.
class Greeter:
def greet(self): return 'Hello'
class FormalGreeter(Greeter):
def greet(self): return 'Good day'
print(FormalGreeter().greet())All lessons in this course
- Single Inheritance
- Method Overriding and super()
- Multiple Inheritance and MRO
- Polymorphism and Duck Typing