Java Reference
In-Depth Information
Display 5.13
Assignment Operator with Class Type Variables (part 2 of 2)
variable2.set("Josephine", 1);
variable1
4068
variable2
4068
Someplace else in memory:
4068
Josephine
1
assignment
with variables
of a class type
Note that when you use the assignment operator with variables of a class type, you
are assigning a reference (memory address), so the result of the following is to make
variable1 and variable2 two names for the same object:
variable2 = variable1;
A variable of a class type stores a memory address, and a memory address is a
number. However, a variable of a class type cannot be used like a variable of a number
type, such as int or double . This is intentional. The important property of a memory
address is that it identifies a memory location. The fact that the implementors used
numbers, rather than letters or strings or something else, to name memory locations
is an accidental property. Java prevents you from using this accidental property to
stop you from doing things such as obtaining access to restricted memory or otherwise
screwing up the computer.
Class Parameters
Strictly speaking, all parameters in Java are call-by-value parameters. This means
that when an argument is plugged in for a parameter (of any type), the argument is
evaluated and the value obtained is used to initialize the value of the parameter. (Recall
that a parameter is really a local variable.) However, in the case of a parameter of a
 
 
Search WWH ::




Custom Search