package cn.itcast_01; /* * 有五个学生,请把这5个学生的信息存到数组中,并遍历数组,获得每个学生的信息。 * 学生:Student * 成员变量:name,age * 构造方法:无参,带参 * 成员方法:getXxx()/setXxx() * * 分析: * A:创建学生类 * B:创建学生数组 * C:创建5个学生对象,并赋值 * D:把五个学生对象放到数组中, * E:遍历学生数组。 * */ public class ObjectArrayDemo { public static void main(String[] args) { //创建数组 Student [] arr = new Student[5]; //创建五个学生对象 Student s1 = new Student("林青霞",28); Student s2 = new Student("风清扬",29); Student s3 = new Student("赵雅芝",30); Student s4 = new Student("孙允珠",25); Student s5 = new Student("黄婷婷",24); //将对象赋给数组 arr[0] = s1; arr[1] = s2; arr[2] = s3; arr[3] = s4; arr[4] = s5; for(int i=0;i<5;i++){ //System.out.println(arr[i]); System.out.println(arr[i].getName()+","+arr[i].getAge()); } } }