What is the relationship between composition and inheritance, often described as 'has-a' vs 'is-a'?

Practice this question from Quiz: OOPS Revision Sheet, with options and an explanation.

Question

What is the relationship between composition and inheritance, often described as 'has-a' vs 'is-a'?

Option A

Composition represents an 'is-a' relationship, while inheritance represents a 'has-a' relationship.

Option B

Both composition and inheritance represent 'is-a' relationships.

Option C — Correct answer

Composition represents a 'has-a' relationship, while inheritance represents an 'is-a' relationship.

Composition models a 'has-a' relationship (e.g., a Car has an Engine), while inheritance models an 'is-a' relationship (e.g., a Dog is an Animal).

Option D

Both composition and inheritance represent 'has-a' relationships.

Quiz: OOPS Revision Sheet

All questions · Previous question · Next question

Open on QuizMaker