8.7 Notes on Set and Get Methods

As you know, a class’s private fields can be manipulated only by its methods. A typical manipulation might be the adjustment of a customer’s bank balance (e.g., a private instance variable of a class BankAccount) by a method computeInterest. Set methods are also commonly called mutator methods, because they typically change an object’s state—i.e., modify the values of instance variables. Get methods are also commonly called accessor methods or query methods.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.