标签:容器 main stat 遍历 void setname 1.3 ret div
package com.xuweiwei; /** * 学生类 */ public class Student { private String name; private Integer age; public Student() { } public Student(String name, Integer age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } @Override public String toString() { return "Student{" + "name=‘" + name + ‘\‘‘ + ", age=" + age + ‘}‘; } }
package com.xuweiwei; /** * 我有5个学生,请把这5个学生的信息存储到数组中,并遍历数组,获取到每一个学生的信息 */ public class ObjectArrayDemo { public static void main(String[] args) { Student s1 = new Student("a",8); Student s2 = new Student("b",9); Student s3 = new Student("c",10); Student s4 = new Student("d",11); Student s5 = new Student("e",12); Student[] students = {s1,s2,s3,s4,s5}; for (int i = 0; i < students.length; i++) { Student s = students[i]; System.out.println(s); } } }
标签:容器 main stat 遍历 void setname 1.3 ret div
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/9320638.html