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

Answer:

Each object has its own identity, its own instance variables, and its own area(), so there is no confusion about which variables are which.


Slightly Different Program

If this is confusing, remember that object oriented programming is supposed to imitate the real world. Think of some objects of the real world, say objects of the class Human. Each object has its own identity (ie. Bob is a different individual from Jill) even though each has parts that have the same name.

Below is a slightly different version of the program.


public class TestCone
{
  public static void main( String[] args ) 
  {
    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() );

  }
}

QUESTION 16:

How does this program differ from the previous program?


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