public class Foo extends Blue { // method1 - blue 1 public void method2() { System.out.println("foo 2"); } public String toString() { return "foo"; } } ============ public class Blue extends Moo { // method2 - "moo 2" // toString - "moo" public void method1() { System.out.println("blue 1"); } } ============ public class Shoe extends Foo { // method2 - "foo 2" // toString - "foo" public void method1() { System.out.println("shoe 1"); } } ============ public class Moo { // base class public void method1() { System.out.println("moo 1"); } public void method2() { System.out.println("moo 2"); } public String toString() { return "moo"; } } =============== Moo[] elements = {new Shoe(), new Foo(), new Moo(), new Blue()}; for (int i = 0; i < elements.length; i++) { Shoe Foo Moo Blue System.out.println(elements[i]); foo foo moo moo elements[i].method1(); shoe 1 blue 1 moo 1 blue 1 elements[i].method2(); foo 2 foo 2 moo 2 moo 2 System.out.println(); }