Skip to content

Instantly share code, notes, and snippets.

@alexpana
Created July 17, 2015 06:36
Show Gist options
  • Save alexpana/b797c8da5c4f1ea9cd8a to your computer and use it in GitHub Desktop.
Save alexpana/b797c8da5c4f1ea9cd8a to your computer and use it in GitHub Desktop.
java puzzlers
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 {
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"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment