Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal(object):
- def __init__(self, sound):
- self.sound = sound
- def make_sound(self):
- print "I am a", self.__class__.__name__
- print "and I go", self.sound
- class Dog(Animal):
- def __init__(self, sound='bark'):
- super(Dog, self).__init__(sound)
- class Duck(Animal):
- pass
- # This is bad form, since Animal.make_sound is an instance method
- class Monster(Animal):
- def make_sound(self):
- Animal.make_sound(self)
- dog = Dog()
- dog.make_sound()
- duck = Duck('quack')
- duck.make_sound()
- monster = Monster('ARGH')
- monster.make_sound()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement