// Speaker Example // Test the Cat, Dog and Person classes. // Also create an array of Speaker objects // and test the Speak method for them. public class TestSpeaker { public static void main(String[ ] args) { Animal a = new Animal( ); // Declare and instantiate objects. Dog x = new Dog("Fido"); Cat y = new Cat("Felix"); Person z = new Person("Alice", 'F', 25); // Test Philosophize method. System.out.println("Test Philosophize method."); z.Philosophize(); System.out.println(); // Print objects using ToString methods. System.out.println("Print objects using ToString methods."); System.out.println(x); System.out.println(y); System.out.println(z); System.out.println(); // Create array of Speaker; Speaker[] s = new Speaker[3]; // Each object implements Speaker so can be // assigned to a speaker array. s[0] = x; s[1] = y; s[2] = z; // Test speaker methods. System.out.println("Test speaker methods."); for(int i = 0; i <= 2; i++) s[i].speak(); } } // Output: