Main {{ public static void p(String s){ System.out.print(s); } public static void main(String args[]) throws Exception { Start start = Start.parse(System.in); // some sample functionality p(start.display() + "\n"); p(start.print() + "\n"); p(start.toStr() + "\n"); System.out.println(start.equals(start)); p(start.magic().display() + "\n"); } }} Start {{ // magically replace apples by oranges and vice versa // and keep the rest of the structure the same public Start magic() { return new Traversal(new Bc(){ Orange combine(Apple a){return new Orange();} Apple combine(Orange o){return new Apple();} }). traverse(this); } }}