OnJava8-Examples/staticchecking/NoBasePetSpeak.py
Bruce Eckel 88dbdbbbcb update
2015-05-18 23:05:30 -07:00

28 lines
474 B
Python

#: staticchecking/NoBasePetSpeak.py
# Speaking pets without base classes:
class Cat:
def speak(self):
print("meow!")
class Dog:
def speak(self):
print("woof!")
class Bob:
def bow(self):
print("thank you, thank you!")
def speak(self):
print("Welcome to the neighborhood!")
def drive(self):
print("beep, beep!")
def command(pet):
pet.speak()
pets = [ Cat(), Dog(), Bob() ]
for pet in pets:
command(pet)
#:~