go to previous page   go to home page   go to next page hear noise

Answer:

A variable of a primitive type contains the actual data, not information on where the data is.


Two Kinds of Variables

class EgString
{

  public static void main ( String[] args )
  {
    String str;
    
    str = new String( "The Gingham Dog" );

    System.out.println( str );
  }
}

A reference variable does not contain the actual object, just a way to find it.

When the statement

System.out.println( str );

is executed, the reference in str is used to find the object and to get the data to be printed.

There are two kinds of variables in Java:

 Characteristics
primitive variableContains the actual data.
reference variableContains information on how to find the object.

There are only eight primitive types, so there are only eight types of primitive variables. Most variables in a sizeable program are reference variables.


QUESTION 7:

What is the object str ?