ABCD

Category: Polymorphism
Author: Stuart Reges
Book Chapter: 9.3
Problem: ABCD
  Assume the following classes have been defined:

        public class A extends D {
            public String toString() {
                return "a";
            }
        
            public void method1() {
                System.out.println("a 1");
            }
        }
        
        public class B extends C {
            public String toString() {
                return "b";
            }
        }
        
        public class C extends D {
            public void method1() {
                System.out.println("c 1");
            }
        }
        
        public class D {
            public String toString() {
                return "d";
            }
        
            public void method1() {
                System.out.println("d 1");
            }
        
            public void method2() {
                System.out.println("d 2");
            }
        }
        
   Consider the following code fragment:

        D[] 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?  (you may write the output as a series
   of 3-line columns in order from left to right)