forked from benelog/java-concurrency
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorPoint.java
42 lines (35 loc) · 929 Bytes
/
ColorPoint.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package jpz.puzzle51;
class Point {
protected final int x, y;
private 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 final synchronized String toString() {
if (name == null) {
name = makeName();
}
return name;
}
}
public class ColorPoint extends Point {
private final String color;
ColorPoint(int x, int y, String color) {
super(x, y);
this.color = color;
}
protected String makeName() {
return super.makeName() + ":" + color;
}
public static void main(String[] args) {
System.out.println(new ColorPoint(4, 2, "purple"));
}
}