import java.util.*; class GD6 { public static void main(String[] args) { ArrayList<Person> a = new ArrayList<Person>(); a.add(new Person("a")); a.add(new Person("b")); a.add(new Person("c")); ArrayList<Stu> al1 = new ArrayList<Stu>(); al1.add(new Stu("A")); al1.add(new Stu("B")); al1.add(new Stu("C")); printCln(a); } public static void printCln(ArrayList<Person> al) { Iterator<Person> it = al.iterator(); while(it.hasNext()) { System.out.println(it.next().getName()); } } } class Person { String name; String getName() { return this.name; } Person(String name){ this.name = name; } } class Stu extends Person { String name; Stu(String name) { super(name); } }
时间: 2024-10-28 21:25:56