Object-Oriented Programming · Question 5 · Easy

A Car object contains an Engine object. This "has-a" relationship is best modelled using:

  1. Inheritance
  2. Method overriding
  3. Composition (or aggregation)
  4. Interface implementation
Answer and explanation

Answer: C. Composition (or aggregation)

Explanation: A "has-a" relationship is modelled by holding a reference to another object (composition or aggregation). Inheritance models an "is-a" relationship.

Previous: Which statement about constructors in Java is correct? · Next: What is the output of the following Java code?

Practise object-oriented programming

Try a fresh set of object-oriented programming questions with an explanation after every answer, free and without signing up: Object-Oriented Programming practice. Or sit a full placement mock test.

More object-oriented programming questions

More technical & programming practice

DBMS · SQL · Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge