public class CastTest { public static void main(String[] args) { ColorPoint cp = new ColorPoint(1, 2, "green"); Point p = cp; // ワイドニング p.print(); // 次の行をコメントアウトすると実行時エラー // p = new Point(3, 4); ColorPoint cp2 = (ColorPoint)p; // ナローイング cp2.color = "red"; cp2.print(); } }