2.4 Encapsulation
Introduction
Encapsulation hides an object's internal state behind a controlled interface. In Java, this typically means making fields `private` and exposing controlled access through public "getter" and "setter" methods, which can validate input or compute derived values instead of allowing direct, unchecked access.
Key Concepts
Java Syntax
Code Examples
`balance` cannot be modified directly from outside the class. `deposit` is the only way to increase it, and it validates that the amount is positive first.