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
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:
assignment
with variables
of a class type
variable2 = variable1;
A variable of a class type stores a memory address, and a memory address is a num-
ber. 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 pre-
vent 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 evalu-
ated and the value obtained is used to initialize the value of the parameter. (Recall that
 
Search WWH ::




Custom Search