Repaso
EspaƱol

class Dog(Animal): expresses which relationship?

Options

  1. Dog HAS an Animal (composition)
  2. Dog IS an Animal (inheritance) (Correct option)
  3. Dog and Animal are unrelated types
  4. Animal IS a Dog (inheritance)

Answer

Dog IS an Animal (inheritance)

Why

This is inheritance: Dog is a kind of Animal. Dog automatically gets Animal's attributes and methods, and can add new ones or override (replace) existing ones.

Use it only when 'X is a Y' is really true. For 'X has a Y' use composition (an attribute).

Remember

Inheritance = 'is a'. Composition = 'has a'.

Key terms

Practice this question in Repaso