Java学习----创建对象的数组

1.初始化数组的长度

2.初始化每个元素对象

3.调用每个对象的方法

public class Student {
private String name; public Student() {} public Student(String name) {
this.name = name;
} public String getName() {
return name;
} public static void main(String[] args) {
// 创建对象数组
Student[] students = new Student[3];
students[0] = new Student("jack");
students[1] = new Student("mary");
students[2] = new Student("wendy"); for (int i = 0; i < 3; i++) {
System.out.println(students[i].getName());
}
}
}
上一篇:[Aaronyang] 写给自己的WPF4.5 笔记19[Visual类图文并茂讲解]


下一篇:[Aaronyang] 写给自己的WPF4.5 笔记24 [与winform交互-flash-DEMO-收尾篇1/6]