Accessors, Mutators and Immutable Classes

double balance = account.getBalance();

account.deposit(1000);

String name = "John Q. Public";
String uppercased = name.toUpperCase(); // name is not changed


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.