这是什么用法呢?
for(Student st:stu){
System.out.println("姓名"+st.getName( )+"年龄"+st.getAge( )+"成绩"+st.getScore( ));
}
说明:其中省略了Student类的构造方法及三个属性的get( ) 和set( ) 方法,Student为类名,stu为定义类对象的数组,如下,
Student stu[]=new Student[5];
stu[0]=new Student("yellowxiaotian",23,100);
stu[1]=new Student("yuanfengmei",23,98);
stu[2]=new Student("lideyi",23,89);
stu[3]=new Student("baobao",23,90);
stu[4]=new Student("aoteman",23,20);
|