把类名写错了,如果你用eclipse的话,尽量自动生成构造方法,这样就不会写错,只要将 调用的类名改成你写的就好了,不报错了看
package com.itheima;
import java.util.*;
class Perrson
{
private String name;;
private int age;
Perrson(String name,int age)
{
this.name = name;
this.age = age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
}
class ArrayListTest2
{
public static void sop(Object obj)
{
System.out.println(obj);
}
public static void main(String[] args)
{
ArrayList al = new ArrayList();
al.add(new Perrson("李四1",30));
al.add(new Perrson("李四2",32));
al.add(new Perrson("李四3",33));
al.add(new Perrson("李四4",35));
Iterator it = al.iterator();
while(it.hasNext())
{
Perrson p = (Perrson)it.next();
sop(p.getName()+"::"+p.getAge());
}
}
} |