如何在java中的类数组中输入?

时间:2016-10-05 20:58:29

标签: java class oop web

我是java新手,这是我们的第一个任务,但我现在还不清楚为什么我们的老师没有将一个类对象数组传递给Add Student方法,而是将对象数组创建为私有,只是传递了名称数组。我现在可以如何添加学生数据

  public class StudentManagement {
    private Student students [] ;
    private int CAPACITY ;
    private int CURRENT_POSITION;
    public StudentManagement(){
        CAPACITY = 3;
        CURRENT_POSITION = 0;
        students = new Student[CAPACITY];
    }

    public void addStudent(Student student){


    }

1 个答案:

答案 0 :(得分:1)

如图灵85所评论,请与您的导师联系,了解这些概念。

此数组可容纳3个对象(CAPACITY)。

CURRENT_POSITION是您要添加对象的地方。

您可以尝试类似于此..

public void addStudent(Student student) {
    if (CURRENT_POSITION < CAPACITY) {
        students[CURRENT_POSITION] = student;
        CURRENT_POSITION++;
    }
}