Which technique specifically hides an object's internal implementation details from external clients (information hiding)?

Difficulty: Easy

Correct Answer: Encapsulation

Explanation:


Introduction / Context:
Information hiding is a core object-oriented principle. By exposing public behaviors while protecting internal state and implementation, we reduce coupling and make systems easier to maintain. The OO pillar directly addressing this is encapsulation.



Given Data / Assumptions:

  • We distinguish among encapsulation, inheritance, and polymorphism.
  • Encapsulation is about visibility and access control; inheritance is about type hierarchies; polymorphism is about dynamic behavior under a common interface.


Concept / Approach:
Encapsulation bundles data and methods, restricting access to internal representation through access modifiers and well-defined interfaces. Clients interact through public methods without knowledge of the underlying details.



Step-by-Step Solution:

Identify which pillar hides internals: encapsulation.Confirm that inheritance and polymorphism do not primarily address information hiding.Select encapsulation as the precise answer.


Verification / Alternative check:
Consider swapping an internal data structure (e.g., array to list) within a class; with encapsulation, the public API remains stable and clients remain unaffected.



Why Other Options Are Wrong:
Polymorphism changes behavior across types, not visibility.
Inheritance promotes reuse via type hierarchies but can even expose internals to subclasses if misused.
All of the above is too broad; only encapsulation directly targets information hiding.



Common Pitfalls:
Equating “private” with true encapsulation; real encapsulation also includes designing a coherent public interface.



Final Answer:
Encapsulation

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion