Bruce Eckel 88dbdbbbcb update
2015-05-18 23:05:30 -07:00

22 lines
312 B
Python

#: staticchecking/PetSpeak.py
# Speaking pets in Python
class Pet:
def speak(self): pass
class Cat(Pet):
def speak(self):
print("meow!")
class Dog(Pet):
def speak(self):
print("woof!")
def command(pet):
pet.speak()
pets = [ Cat(), Dog() ]
for pet in pets:
command(pet)
#:~