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());
        }
    }
}

 

版权声明:本文为dragon1013原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/dragon1013/p/5054327.html