/* Java class that, together with child classes, demonstrates polymorphism ** and dynamic dispatch. */ public class Animal { public String utterance() { return "silence"; } /* Prints the result of the utterance() method the specified # of times. ** Note that the version of utterance() that is called here depends ** upon which class the "target object" is a (direct) member of. */ public void speak(int n) { for (int i=0; i != n; i++) { System.out.print(this.utterance() + ' '); } System.out.println(); } }