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

Is it clear what the phrase "the object a" means?

Answer:

Yes, even though the phrase is a little bit deceptive. One should really say "the object referenced by a," or "the object referred to by a," but usually people use the shorter phrase and expect you to know what they mean.


The toString() Method

The example program does very little that is visible on the monitor screen. It would be nice to print something out. The bytes that make up an object cannot be sent directly to the monitor because they are not ASCII character data. For example, the two ints of a Point use a data type that can't be sent directly to a monitor. Of course, the methods of an object are in Java bytecode, which makes no sense to a monitor, either.

Luckily, there is a method defined in class Point that can be used to create a printable String for a Point object.

The toString() method of a Point object creates a String object, which can then be printed. Look at the documentation:


    public String toString();   // returns character data that can be printed
      |      |        |
      |      |        +--- this is the method name.  It takes no parameters.
      |      |
      |      +--- this says that the method returns a String object
      |
      +--- anywhere you have a Point object, you can use this method

All objects have their own toString() method, so it is possible to print out something for any object your program has created. (Often, though, the String is not very useful.)


QUESTION 7:

(Review: ) What is a parameter?