// Zorah Fung, CSE 143 // Demonstrates polymorphism through interfaces: the addAndPrint method will // work for any object type that implements the List interface! public class ListClient { public static void main(String[] args) { List list1 = new ArrayList(); addAndPrint(list1); List list2 = new LinkedList(); addAndPrint(list2); } // Calls several methods on a List // pre: list is not null public static void addAndPrint(List list) { list.add("Matt"); list.add("Erika"); list.add("Bella"); list.add(1, "Ryan"); list.set(1, "Aaron"); System.out.println(list); list.remove(0); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } } }