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

Answer:

A single reference variable cone is used in turn for each object.


Garbage

First Cone as Garbage

The output to the screen of this program is the same as the previous. However, when a reference to the second Cone object is assigned to cone, the first Cone object becomes garbage.

    Cone cone  = new Cone( 1.2, 4.56 );
    System.out.println( "cone area: " + cone.area() 
      + " volume: " + cone.volume() );

    cone      = new Cone( 3.0, 1.2 );
    System.out.println( "cone area: " + cone.area() 
      + " volume: " + cone.volume() );

The picture shows the situation just after the second Cone is constructed. The first Cone no longer has a reference to it, so it is now garbage.


QUESTION 17:

(Review Questions:)

  1. Do the instance variables of an object hold values for the lifetime of the object?
  2. Do the parameters of a constructor hold values for the lifetime of the object?

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