Skip to main content

/docs/images/banner.jpg

Python

Function overriding

Implement function overriding in Python, where a child class provides its own implementation of a method that is already defined in the parent class.

class Parent:
def method(self):
print("Parent Method")

class Child(Parent):
def method(self):
print("Child Method")

child = Child()
child.method()

# Output:
# Child Method
note

To compile and run the program, you can use the following commands:

python3 foo.py