Definition. Getter

[comp1110-3G]

In Example [comp1110-3E], our balance field is private, so we provide getter methods to allow the outside world to read the state without being able to write to it directly.

public int getBalance() { return this.balance; }

Note that we do not provide a setBalance method. This ensures that the only way to change the balance is through valid actions like deposit().

bars magnifying-glass caret-down plus minus arrow-right xmark