Object-Oriented Programming (OOP)
What is Composition primarily used for?
- A. The process by which objects communicate with one another by invoking each other's methods.
- B. A design principle in which a class is built using instances of other classes as components, forming a 'has-a' relationship. ✓
- C. The practice of restricting direct access to an object's internal data to protect it from unintended interference.
- D. A special method automatically invoked when an object is destroyed, used to release resources.
Correct answer
B. A design principle in which a class is built using instances of other classes as components, forming a 'has-a' relationship.
Explanation
Composition refers to a design principle in which a class is built using instances of other classes as components, forming a 'has-a' relationship.