Python Practice › OOP Programs › Program 14
Method overriding
Write a Python program that demonstrates method overriding.
Output
Sending: Hi Sending: Hi (via email)
Approach
- The child defines a method with the same name;
super()reuses the parent’s version.
Solution
class Notification: def send(self, msg): return f"Sending: {msg}" class EmailNotification(Notification): def send(self, msg): return super().send(msg) + " (via email)" print(Notification().send("Hi"))print(EmailNotification().send("Hi"))Output
Sending: Hi Sending: Hi (via email)
Learn the concept
New to this topic? Read the lesson, then come back.