Skip to main content
Lesson 12 - Object References
ZIPPDF (letter)
Lesson MenuPreviousNext
  
Variable Versus Object Reference Assignment page 5 of 10

  1. Notice that there is a difference between the two statements:

    primitiveValue = 18234;

    and

    str = new String("example string");

    In the first statement, primitiveValue is a primitive type, so the assignment statement puts the data directly into it. In the second statement, str is an object reference variable (the only other possibility) so a reference to the object is put into that variable.

  2. There are only variables containing primitive data and variables containing object references, and each contains a specific kind of information. A variable will never contain an object:

    Kind of VariableInformation it ContainsWhen on the left of "="
    primitive variableContains actual dataPrevious data is replaced with new data.
    reference variableContains information on how to find an object.Old reference is replaced with a new reference

  3. The two types of variable are distinguished by how they are declared. Unless it was declared to be of a primitive type, it is an object reference variable. A variable will not change its declared type.


Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.