Exercise 13.1

Does anything about these two classes “smell” wrong?

class Dog:     
    def __init__(self, name='', bites=True):
        self.name = name
        self.genus = 'canis'
        self.bites = bites     
    def get_sound(self):
        return 'woof'

class Cat:
    def __init__(self, name, lives=9):
        self.name = name
        self.genus = 'felis'
        self.lives = lives
    def get_sound(self):
        return 'meow'

Exercise 13.2

Draw an appropriate hierarchy for the following.

Exercise 13.3

Build an hierarchy that distinguishes dogs, cats and fleas, supporting the following features.

Exercise 13.4

Label the following as either instantiation, inheritance or composition.

  1. dog — Phydeaux
  2. animal — dog
  3. Fifi — flea
  4. Phydeaux — Fifi