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

Answer:

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


Two Kinds of Variables

public 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 how 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.


QUESTION 7:

In the above program, what is the object str ?


go to previous page   go to home page   go to next page