class Dog(Animal): expresses which relationship?
Options
- Dog HAS an Animal (composition)
- Dog IS an Animal (inheritance) (Correct option)
- Dog and Animal are unrelated types
- 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'.