Java Reference
In-Depth Information
}
}
5.3 Objects and references
Variables of a given object type are allocated into the global memory, and
references to these memory structures are stored into the variables. This is to
contrast with variables of primitive types that are manipulated by value . Similar
to array variables, a variable of type object is a reference to that object. That
is, loosely speaking, the variable stores the memory address of this referenced
object. Thus when we write:
Date day1=new Date(23,12,1971);
Date day2=day1;
Display(day2);
day2.mm=6;
Display(day1);
We get:
Date:23/12/1971
Date:23/6/1971
main
day1=new ...
...
day2=day1;
day2.mm=6;
Date@
dd
mm
yyyy
Figure 5.2 Objects are non-
primitive typed structures that are
stored in the program global mem-
ory and manipulated by references
(and not by values)
local memory
(function call stack)
global memory
The date day1 is not copied to day2 , but only their references are copied.
That is, the reference of day2 is assigned to the reference of day1 so that their
object records necessarily match since they refer to the same memory location
as depicted in Figure 5.2.
 
Search WWH ::




Custom Search