Which statement(s) are true? (Choose all that apply.)

  1. Cohesion is the OO principle most closely associated with hiding implementation details

  2. Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs

  3. Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose

  4. Cohesion is the OO principle most closely associated with allowing a single object to be seen as having many types


Correct Option: C

AI Explanation

To answer this question, we need to understand the concept of cohesion in object-oriented programming (OOP).

Cohesion is the measure of how closely the responsibilities and functionality of a class or module are related. It is an important principle in OOP design, as it promotes modularity, maintainability, and reusability.

Let's go through each statement to determine which one(s) are true:

A. Cohesion is the OO principle most closely associated with hiding implementation details. This statement is incorrect. Hiding implementation details is more closely associated with the principle of encapsulation, not cohesion.

B. Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs. This statement is incorrect. Making sure that classes know about other classes only through their APIs is more closely associated with the principle of information hiding, not cohesion.

C. Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose. This statement is true. Cohesion is all about ensuring that a class has a single, well-focused purpose. It means that the responsibilities and functionality of a class should be closely related and focused on achieving a specific goal.

D. Cohesion is the OO principle most closely associated with allowing a single object to be seen as having many types. This statement is incorrect. Allowing a single object to be seen as having many types is more closely associated with the principle of polymorphism, not cohesion.

Based on the explanations above, the correct statement is:

C. Cohesion is the OO principle most closely associated with making sure that a class is designed with a single, well-focused purpose.

Therefore, the correct answer is C.

Find more quizzes: