Object-Oriented Programming · Question 26 · Medium

Object-Oriented Programming question 26

A House is made of Rooms, and the Rooms cannot exist without the House: when the House object is destroyed, its Rooms are destroyed too. This relationship is:

  1. Aggregation
  2. Inheritance
  3. Composition
  4. Association with no ownership
Answer and explanation

Answer: C. Composition

Explanation: Composition is a strong has-a relationship in which the part's lifetime is bound to the whole. In aggregation the parts can exist independently, such as Players in a Team.

Previous: Which design pattern ensures that a class has only one instance and provides a… · 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