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:
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:
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