public class ColorPoint extends Point { public String[] cs = { "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"}; public String color; @Override public void print() { System.out.printf("", getColor()); // 次の行は super.print(); でも可 System.out.printf("(%d, %d)", x, y); System.out.print(""); } public void setColor(String c) { int i; for (i = 0; i < cs.length; i++) { if (c.equals(cs[i])) { color = c; return; } } // 対応する色がなかったら何もしない。 } public ColorPoint(int x, int y, String c) { super(x, y); setColor(c); if (color == null) color = "black"; } public String getColor() { return color; } }