PCPP-32-101 · Question #1
Select the true statement about composition.
The correct answer is B. Composition allows a class to be projected as a container of different classes. Composition in POO allows a class to act as a container that holds instances of other classes, fostering code reusability and enabling the creation of complex structures by combining simpler components. It establishes a "has-a" relationship, promoting encapsulation and…
Question
Select the true statement about composition.
Options
- AComposition extends a class's capabilities by adding new components and modifying the existing
- BComposition allows a class to be projected as a container of different classes
- CComposition is a concept that promotes code reusability, while Inheritance promotes
- DComposition is based on the has a relation, so it cannot be used together with inheritance
How the community answered
(27 responses)- A7% (2)
- B89% (24)
- C4% (1)
Explanation
Composition in POO allows a class to act as a container that holds instances of other classes, fostering code reusability and enabling the creation of complex structures by combining simpler components. It establishes a "has-a" relationship, promoting encapsulation and flexibility, as the container class can access the public interface of the contained classes, but not their internal details, facilitating modular and adaptable code design.
Topics
Community Discussion
No community discussion yet for this question.