// Simulating casts with methods class Castable extends Object { Castable() { super(); } Bool instanceOfC() { return new False(); } Bool instanceOfD() { return new False(); } C castToC() { return this.castToC(); } D castToD() { return this.castToD(); } } class C extends Castable { Integer x; C(Integer x) { super(); this.x = x; } Bool instanceOfC() { return new True(); } C castToC() { return this; } } class D extends C { Integer y; D(Integer x, Integer y) { super(x); this.y = y; } Bool instanceOfD() { return new True(); } D castToD() { return this; } } class Feath4 extends Object { public static void main(String[] args) { C c = new D(new Integer(1), new Integer(2)); System.out.println(c.x); D d = c.castToD(); System.out.println(d.x + " " + d.y); } }