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

Answer:

  1. Do the instance variables of an object hold values for the lifetime of the object?
    • Yes — an object has state (its unique characteristics.) The state is kept in instance variables.
  2. Do the parameters of a constructor hold values for the lifetime of the object?
    • No — the parameters of a constructor are part of a temporary "message" to the constructor. After the parameters have been used, they are gone.

Possible Errors

Here is version of Cone. Is anything wrong?

// file: Cone.java
//
public class Cone
{
  private double radius;  // radius of the base
  private double height;  // height of the cone
  
  public Cone( double R, double H )
  {
    radius = R;
    height = H;
  }
  
  public double volume()
  {
    return Math.PI*R*R*H/3.0;  
  }
  
}

QUESTION 18:

Examine the program. Is there anything wrong?


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