Difficulty: Easy
Correct Answer: Encapsulation
Explanation:
Introduction / Context:
In object-oriented programming (OOP), class design bundles state (data) with behavior (member functions). Understanding the names and roles of core OOP principles helps you reason about program structure, maintainability, and security. This question asks which term specifically denotes the wrapping of data and functions together in one cohesive unit.
Given Data / Assumptions:
Concept / Approach:
Encapsulation is the OOP principle that binds data and the methods that operate on that data into a single unit (typically a class), while controlling access via access specifiers (private, protected, public). Encapsulation enables information hiding: clients interact through a stable public interface while internal representation remains private, enabling safer refactoring and preserving invariants. Although related, abstraction is about exposing essential features while hiding complexity; inheritance enables reuse across hierarchies; polymorphism enables substitutability via virtual dispatch and overloading.
Step-by-Step Solution:
Verification / Alternative check:
Consider a class with private fields and public getters/setters or behavior methods. Users of the class cannot directly manipulate internals, confirming encapsulation. Abstraction may also be present, but the “wrapping together” wording points chiefly to encapsulation.
Why Other Options Are Wrong:
Abstraction: emphasizes essential interface, not bundling per se.
Inheritance: reuses and extends behavior across classes.
Polymorphism: allows the same interface to represent different concrete types.
Common Pitfalls:
Final Answer:
Encapsulation
Discussion & Comments