Certified Professional in Python Programming (PCPP-32-101) — Question 34
Select the true statement about composition.
Answer options
- A. Composition extends a class’s capabilities by adding new components and modifying the existing ones
- B. Composition allows a class to be projected as a container of different classes
- C. Composition is a concept that promotes code reusability, while Inheritance promotes encapsulation
- D. Composition is based on the has a relation, so it cannot be used together with inheritance
Correct answer: B
Explanation
Option B is correct because composition indeed allows a class to act as a container for multiple classes, emphasizing a 'has a' relationship. Option A is incorrect because it describes modifications rather than the core purpose of composition. Option C misrepresents the primary goals of both concepts, and Option D is wrong as composition can coexist with inheritance; they are not mutually exclusive.