本帖最后由 王红霞 于 2012-7-18 14:09 编辑
class Person
{
private String name;
private int age;
Person(String name,int age)
{
this.name=name;
this.age=age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
}
class ArrayListTest
{
public static void sop(Object obj)
{
System.out.println(obj);
}
public static void main(String[] args)
{
ArrayList al=new ArrayList();
al.add(new Person("ll01",22));
al.add(new Person("ll02",23));
al.add(new Person("ll03",24));
al.add(new Person("ll04",26));
Iterator it=al.iterator();
while(it.hasNext())
{
Object obj=it.next();
Person p=(Person)obj;//这是咋么个情况?是如何定义的?谁能帮我详细走一遍?(Person)obj是什么意思?
sop(p.getName()+"::"+p.getAge());
}
}
}
|