Java Reference
In-Depth Information
< Day Day Up >
Puzzle 51: What's the Point?
This program has two immutable value classes , which are classes whose instances represent values.
One class represents a point on the plane with integer coordinates, and the second class adds a bit of
color to the puzzle. The main program creates and prints an instance of the second class. What does
the program print?
class Point {
private final int x, y;
private final String name; // Cached at construction time
Point(int x, int y) {
this.x = x;
this.y = y;
name = makeName();
}
protected String makeName() {
return "[" + x + "," + y + "]";
}
public final String toString() {
return name;
}
}
public class ColorPoint extends Point {
 
 
Search WWH ::




Custom Search