// Example: Interfaces // Module: speaker // Source code file: Test1.java // Create classes that implement the Speaker interface. import java.util.ArrayList; // Example: Interfaces // Module: speaker // Source code file: Test1.java // Create classes that implement the Speaker interface. public class Test1 { public static void main(String[] args) { // Create objects. Cat c = new Cat("Simba"); Dog d = new Dog("Mollie"); Person p = new Person("Alice"); // Print objects. System.out.println(c); System.out.println(d); System.out.println(p); System.out.println( ); // Call speak methods of all objects // that implement Speaker interface. c.speak( ); d.speak( ); p.speak( ); // An object that implements the Speaker // interface can also have other instance methods. p.philosophize( ); // Add objects to the ArrayList collection that // implement the Speaker interface. ArrayList col = new ArrayList(10); col.add(c); col.add(d); col.add(p); // Print each object in collection and call // its speak method. for(Speaker obj : col) { System.out.println( ); System.out.println(obj); obj.speak( ); } } }