- import java.util.*;
- class Person
- {
- private String name;
- Person(String name)
- {
- this.name=name;
- }
- public String getName()
- {
- return name;
- }
- }
- class Student extends Person
- {
- Student(String name)
- {
- super(name);
- }
- }
- public class Gener6
- {
- public static void main(String[]args)
- {
- ArrayList<Person>al =new ArrayList<Person>();
- al.add(new Person("abc01"));
- al.add(new Person("abc02"));
- al.add(new Person("abc03"));
- al.add(new Person("abc04"));
- print(al);
- System.out.println();
- ArrayList<Student>al2=new ArrayList<Student>();
- al2.add(new Student("def01"));
- al2.add(new Student("def02"));
- al2.add(new Student("def03"));
- al2.add(new Student("def04"));
- print(al2);
- }
- public static void print(Collection<? extends Person>al)
- {
- Iterator<? extends Person> it=al.iterator();
- while(it.hasNext())
- {
- System.out.print(" "+it.next().getName());
- }
- }
- }
复制代码 错误好像是说33行找不到特定方法,真不知道原因是什么? |
|