import java.util.ArrayList;
import java.util.Iterator;
class Student
{
private int age;
private String name;
Student(){};
Student(String name,int age)
{
this.name=name;
this.age=age;
}
public void setAge(int age)
{
this.age=age;
}
public int getAge()
{
return age;
}
public void setAge(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public void method()
{
System.out.println("name="+name+"......."+"age="+age);
}
}
class Test2
{
public static void main(String[] args)
{
Student s1=new Student("林青霞",50);
Student s2=new Student("刘亦菲",20);
Student s3=new Student("张柏芝",25);
Student s4=new Student("梁咏琪",28);
Student s5=new Student("陈慧琳",23);
ArrayList al=new ArrayList();
al.add(s1);
al.add(s2);
al.add(s3);
al.add(s4);
al.add(s5);
Iterator it=al.iterator();
while(it.hasNext())
{
Student ss=(Student)it.next();
ss.method();
}
}
}
|
|