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);
}
}
class FanxingDemo1
{
public static void main(String[] args)
{
ArrayList<Person> a1 = new ArrayList<Person>();
a1.add(new Person("zhangsan"));
a1.add(new Person("zhnsagk"));
a1.add(new Person("lisi"));
a1.add(new Person("werrda"));
ArrayList<Student> a2 = new ArrayList<Student>();
a2.add(new Student("xuesheng1..."));
a2.add(new Student("xuesheng2..."));
a2.add(new Student("xuesheng3..."));
a2.add(new Student("xuesheng4..."));
sop(a1);
}
public static void sop(ArrayList<? super Student> a)
{
Iterator<? super Student> i = a.iterator();
while(i.hasNext())
{
//System.out.println(i.next());
System.out.println(i.next().getName());
}
}
}
为什么最后访问不到Person类里面的getName()方法吗,,,诧异呀,,,谁来破解一些,,,我是小白呀
|
|