Java Reference
In-Depth Information
more than once? Or if you could fix a mistake rather than having to retype the
command in its entirety? Many command line interfaces have an option to do just
that, by using the up and down arrow keys to recall old commands and the left and
right arrow keys to edit lines. You can also perform file completion. For example,
to select the file BankAccount.java , you only need to type the first couple of
letters and then hit the ȒTabȓ key.
The details depend on your operating system and its configurationȌexperiment on
your own, or ask a Ȓpower userȓ for help.
3.7 Categories of Variables
We close this chapter with two sections of a more technical nature, examining
variables and parameters in some detail.
You have seen three different categories of variables in this chapter:
1. Instance fields (sometimes called instance variables), such as the balance
variable of the BankAccount class
2. Local variables, such as the newBalance variable of the deposit method
3. Parameter variables, such as the amount variable of the deposit method
104
105
These variables are similar in one respectȌthey all hold values that belong to specific
types. But they have a couple of important differences. The first difference is their
lifetime.
Instance fields belong to an object. Parameter variables and local variables belong
to a methodȌthey die when the method exits.
An instance field belongs to an object. Each object has its own copy of each instance
field. For example, if you have two BankAccount objects (say,
harrysChecking and momsSavings ), then each of them has its own balance
field. When an object is constructed, its instance fields are created. The fields stay
alive until no method uses the object any longer. (The Java virtual machine contains
an agent called a garbage collector that periodically reclaims objects when they are
no longer used.)
Search WWH ::




Custom Search