- /*、请编写程序,将3个学生的信息存储到数组中,并遍历数组,获取得到每一个学生信息*/
- public class DemoDay16Test02 {
- public static void main(String[] args) {
- Student s = new Student(8,"小明"); //创建引用类对象
- Student s1 = new Student(12,"小红");
- Student s2 = new Student(15,"小李");
-
- Student [] arr = new Student[3]; //创建引用类数组 赋值
- arr[0]=s;
- arr[1]=s1;
- arr[2]=s2;
-
- for (int i = 0; i < arr.length; i++) {
- Student stu = arr[i]; //把每个数组的地址值赋给对象
- System.out.println(stu.getAge()+""+stu.getName()); // 用getset方法实现
- }
复制代码 |
|