Home Segments Top Top Previous Next

183: Mainline

If a variable or parameter is of primitive type, then you can think of it as a label for a chunk of memory that holds a value.

Memory allocated for primitive-type variable 
  | 
  v 
*---------* 
|  Value  | 
*---------* 

If, however, a variable or parameter is of reference type, then you can think of it as a label for a chunk of memory that holds the address of a chunk of memory that holds an instance. That is, a reference-type variable is a label for a chunk of memory that refers to another chunk of memory.

Memory allocated for reference-type variable 
  | 
  v 
*---------*           *-----------* 
| Address | --------> | Instance  | 
*---------*           |           | 
                      |           | 
                      *-----------* 

You need to understand a nuance of the primitive–reference distinction described in the following segments.