Encapsulation
Bundling data and methods within classes while hiding internal implementation details through access modifiers. Encapsulation protects object state from invalid modifications and reduces external code dependencies. Public interfaces define how code interacts with objects, while private implementation details remain hidden. Encapsulation improves maintainability by localizing change impacts.
Real World
A bank account at Barclays keeps your balance as a private attribute — you can only change it through deposit() and withdraw() methods, which validate amounts, preventing anyone from setting their balance to £1 million directly.
Exam Focus
Explain why attributes are private and accessed via getters/setters — marks require justification, not just description.
How well did you know this?