Do it ߏ
E3CSchools - Home
Python Installation
# Define a parent class class Animal: def __init__(self, name): self.name = name def speak(self): raise NotImplementedError("Subclass must implement abstract method") # Define a child class inheriting from Animal class Dog(Animal): def speak(self): return f"{self.name} says Woof!" # Define another child class inheriting from Animal class Cat(Animal): def speak(self): return f"{self.name} says Meow!" # Create instances of the child classes dog = Dog("Buddy") cat = Cat("Whiskers") # Call the speak method on instances print(dog.speak()) # Output: Buddy says Woof! print(cat.speak()) # Output: Whiskers says Meow!