Excerpted from a mini-course introducing Java to students who already know other languages.
References
You can see that variables of type Book, refer to to objects. We call such variables "reference variables". And we call the values of such variables "reference values".
A reference variable can hold the address at which an object is located.
A reference value is such an address.
There is nothing wrong with copying the address of an object from one variable to another.
In the following example, we initialize c
to have the same value as b
.
Principle: Separation of references from objects. Objects and the variables that refer to them are quite separate. Each object may be referred to by one or more references.
C++ programmers will recognize that Java's "reference variables" are the same idea as C++'s "pointer variables".
Examples Shown in Full