Accessors, Mutators and Immutable Classes
Accessor: does not change the state of the implicit parameter
double balance = account.getBalance();
Mutator: modifies the object on which it is invoked
account.deposit(1000);
Immutable class: has no mutator methods (e.g., String)
String name = "John Q. Public";
String uppercased = name.toUpperCase(); // name is not changed
It is safe to give out references to objects of immutable classes; no code can modify the object at an unexpected time
Is the substring method of the String class an accessor or a mutator?
Answer: It is an accessor – calling substring doesn't modify the string on which the method is invoked. In fact, all methods of the String class are accessors.
Is the Rectangle class immutable?
Answer: No – translate is a mutator.