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

Answer:

How many Point objects are created by this program?     One — the object referenced by pt

How many temporary String objects are created by this program?     Two — one temporary String object for each println()


One Object, with Changing Data

changing object contents

The program changes the data inside a Point object using that object's move() method:

import java.awt.*;
class PointEg4
{
  public static void main ( String arg[] )
  {
    Point pt = new Point( 12, 45 );  // construct a Point
    System.out.println( pt );     

    pt.move( -13, 49 ) ;             // change the x and y in the Point
    System.out.println( pt ); 
  }
}

QUESTION 13:

Can a constructor be used to change the data inside an object?