created 12/13/98; revised: 09/23/99, 01/21/00, 07/14/02, 01/19/06
So far, the objects that we have designed have instance variables that are visible outside of the objects. Any code that holds a reference to an object can change the object's instance variables. This is often leads to problems.
A better design enforces encapsulation.
Some (or all) of an object's instance variables are
visible only to the object's own methods.
Code outside of the object cannot access these variables
directly.
This chapter discusses how to use the private
visibility modifier
to do this.
private
and the public
visibility modifiersCheckingAccount
classShould a bank control what software has access to your checking account?