在Eclipse中創建對象數組的步驟如下:
示例代碼:
public class Student {
private String name;
private int age;
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
public class Main {
public static void main(String[] args) {
// 創建Student對象數組
Student[] students = new Student[3];
// 實例化數組中的每個元素
students[0] = new Student("Alice", 20);
students[1] = new Student("Bob", 21);
students[2] = new Student("Charlie", 22);
// 遍歷數組并訪問每個對象的屬性
for (int i = 0; i < students.length; i++) {
System.out.println("Student " + (i+1) + ": " + students[i].getName() + " - " + students[i].getAge());
}
}
}
通過這樣的步驟,在Eclipse中就可以創建對象數組并訪問其中的對象屬性。