提示找不到getName()
import java.util.*;
class fanxing
{
public static void main(String[] args)
{
//ArrayList<Person> a = new ArrayList<Person>();
//a.add(new Person("lixi3"));
//print(a);
ArrayList<Student> a1 = new ArrayList<Student>();
a1.add(new Student("abc1"));
a1.add(new Student("abc2"));
print(a1);
}
public static void print(ArrayList<? super Student> a )
{
Iterator<? super Student> it = a.iterator();
while (it.hasNext())
{
System.out.println(it.next().getName());
}
}
}
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);
}
} |