python-stuff/polymorphism.py

22 lines
394 B
Python
Raw Permalink Normal View History

2021-04-08 23:59:43 +02:00
class Instrument:
def makeSound(self):
print("Nothing happens")
class Guitar(Instrument):
def makeSound(self):
print("Epic guitar sound!!")
class Piano(Instrument):
def makeSound(self):
print("Wonderful piano sound!!")
def startConcert(inst):
inst.makeSound()
i = Instrument()
g = Guitar()
p = Piano()
startConcert(i)
startConcert(g)
startConcert(p)