我有两个类,我的对象类和ListObjectClass
在我的ListObjectClass构造函数中,创建一个对象数组,如下所示:

private ObjectClass[] name;


而且我必须为每个ID创建一个ObjectClass,但是我不知道该怎么做,是否需要在getID()上分别创建一个setID()ObjectClass

ListObject类的构造方法:

private int id;
private float pes;
private int nRegistres;
private RellotgeObjecte[] rellotge;

public LlistaRegistreEsportiu(int n) {

    this.nRegistres = 0;
    rellotge = new RellotgeObjecte[n];

}

最佳答案

您可以将ID作为构造函数的参数传递:

public LlistaRegistreEsportiu(int n, int id) {
    this.nRegistres = 0;
    rellotge = new RellotgeObjecte[n];
    this.id = id;
}

09-26 23:09
查看更多