Previous-year question practice database
Answer
Exam answer
Encapsulation is the wrapping up of data and the functions that operate on that data into a single unit, called a class, so that the data is protected from outside interference.
Example: a class with private data members and public methods to read or change them.
Explanation
Give the definition and add why it matters — encapsulation is the basis of DATA HIDING, achieved by declaring the variables private and providing public methods for controlled access. Keep it apart from abstraction: encapsulation hides DATA, abstraction hides COMPLEXITY. A capsule of medicine is the standard illustration — the contents are wrapped and protected in one unit.
More from Encapsulation
Which of the following is NOT an access specifier?2026Post office is an example for __________ access specifier.2025The access specifier that gives least accessibility is __________.2024Assertion (A): Static method can access static and instance variables.
Reason (R): Static variables can be accessed only by static method.2024A mechanism where one class acquires the properties of another class:2023A method which is a part of a class rather than an instance of the class is termed as:2023