19 lines
377 B
Python
19 lines
377 B
Python
# Demonstrating runtime polymorphism through method overriding
|
|
|
|
class Animal:
|
|
def speak(self):
|
|
return "Some sound"
|
|
|
|
|
|
class Bird(Animal):
|
|
def speak(self):
|
|
return "Tweet"
|
|
|
|
class Dog(Animal):
|
|
def speak(self):
|
|
return "Woof"
|
|
|
|
|
|
print(Animal().speak()) # Some sound
|
|
print(Bird().speak()) # Tweet
|
|
print(Dog().speak()) # Woof |