Abstract Base Class Polymorphism

Mon 10 August 2026
from abc import ABC, abstractmethod

class Shape(ABC):
    @abstractmethod
    def area(self):
        pass

class Rectangle(Shape):
    def area(self):
        return 10 * 5

shape = Rectangle()
print(shape.area())
50


Score: 10

Category: chapter4_polymorphism


Duck Typing

Mon 10 August 2026
class Car:
    def move(self):
        print("Car moving")

class Boat:
    def move(self):
        print("Boat sailing")

def start(vehicle):
    vehicle.move()

start(Car())
start(Boat())
Car moving
Boat sailing


Score: 10

Category: chapter4_polymorphism

Read More

Real-World Polymorphism Example

Mon 10 August 2026
class Notification:
    def send(self):
        print("Sending notification")

class Email(Notification):
    def send(self):
        print("Sending Email")

class SMS(Notification):
    def send(self):
        print("Sending SMS")

def notify(service):
    service.send()

notify(Email())
notify(SMS())
Sending Email
Sending SMS


Score: 10

Category: chapter4_polymorphism

Read More
Page 1 of 1