More about Objects and Classes

The relational operations on primitive data are ==, >=, <=, >, <, and !=. They compare two data values, when those values' type has an ordering. For example, integers are ordered by size or magnitude. The result of a relational operation is a boolean value: either True or False. The relational operators on objects like Strings are different, and they are expressed as methods. Pay special attention to the equality method, equals().

13. One Object, with Changing Data


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


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?