Run
class Animal: def __init__(self, name): self.name = name def speak(self): raise NotImplementedError("Subclass must implement abstract method") def run(self): print(self.name, "is running.") class Dog(Animal): def speak(self): print(self.name, "says Woof Woof!") class Cat(Animal): def speak(self): print(self.name, "says Meow Meow!") dog = Dog("Pigo") cat = Cat("Keto") dog.speak() dog.run() cat.speak() cat.run()
Output