Ernest T
Ernest T

Reputation: 5

Create ID for each object in a ListObjectClass

I have two classes, my object class, and the ListObjectClass. In my constructor of ListObjectClass I create an array of an object looking like this:

private ObjectClass[] name; 

And I have to make an ID for each ObjectClass, but I don't know how can I do that, do I need to make a getID() and setID() on ObjectClass?

Constructor of ListObject Class:

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

public LlistaRegistreEsportiu(int n) {

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

}

Upvotes: 0

Views: 41

Answers (1)

LowKeyEnergy
LowKeyEnergy

Reputation: 652

You can pass the ID as an argument of the constructor:

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

Upvotes: 1

Related Questions