标题: 数组元素为引用类型,并且遍历输出. [打印本页] 作者: Morrfree 时间: 2015-8-13 22:28 标题: 数组元素为引用类型,并且遍历输出. class Student{
private String name;
private int age;
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(String name, int age) {
super();
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
public class StudentTest {
public static void main(String[] args) {
Student s = new Student("李明",20);
Student s1 = new Student("张明",20);
Student s2 = new Student("王明",20);
Student s3 = new Student("周明",20);
Student s4 = new Student("吴明",20);
Student[] ss = new Student[]{s,s1,s2,s3,s4};
for (int i = 0; i < ss.length; i++) {
System.out.println(ss[i].getName()+""+ss[i].getAge());
}
}
}作者: 永飞 时间: 2015-8-13 22:34
写的不催哦作者: Morrfree 时间: 2015-8-17 23:13