Python Practice › OOP Programs › Program 14

Method overriding

EasyOOP Programs · 14 of 48

Write a Python program that demonstrates method overriding.

Advertisement
Output
Sending: Hi
Sending: Hi (via email)

Approach

  1. The child defines a method with the same name; super() reuses the parent’s version.

Solution

Python
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.

More oop programs

← All 48 OOP Programs

Leave a Comment