Variables can change
By their nature, a variable can change its
value. A variable declared for referring to an object of a certain class can refer to any
objects of that class. So such a variable might at one point be referring to one object,
and at another point be referring to a different object.
For example:
//
object variable declaration
BankAccount
accountToBalance;
...
accountToBalance =
account1;
display(
accountToBalance.getBalance() );
accountToBalance =
account2;
display(
accountToBalance.getBalance() );
So at one point during the execution of these
statements, variable accountToBalance was referring to the same object as account1, and in
a later statement accountToBalance was referring to a different object, the one referred
to by account2.
This illustrates:
- a variable can refer to different objects at different times
- two (or more) variables can refer to the same object
Back
to top

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg
|