Verified Jobs Live
Software Engineering & OOP Easy Level ~3 min read

How does encapsulation protect an object’s rules? Explain using a bank account.

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

Encapsulation places state and the operations that control it behind a defined interface. An account should expose deposit and withdrawal methods rather than a freely writable balance. Those methods can reject negative amounts, enforce an overdraft rule, and record transactions. A private field alone is insufficient if a public setter allows arbitrary balances. The goal is to preserve valid states and reduce the number of places that must change when a business rule changes. Monetary values should use an appropriate decimal or minor-unit representation.