ABCD
Category: Polymorphism
Author: Stuart Reges
Book Chapter: 9.3
Problem: ABCD
Assume the following classes have been defined: public class D extends C { public String toString() { return "d"; } public void method2() { System.out.println("d 2"); } } public class B { public String toString() { return "b"; } public void method1() { System.out.println("b 1"); } public void method2() { System.out.println("b 2"); } } public class A extends D { public String toString() { return "a"; } } public class C extends B { public void method1() { System.out.println("c 1"); } } Consider the following code fragment: B[] elements = {new C(), new A(), new D(), new B()}; for (int i = 0; i < elements.length; i++) { System.out.println(elements[i]); elements[i].method1(); elements[i].method2(); System.out.println(); } What output is produced by this code?