0
I don’t understand how to initialize an array that is the class
ItemArray Is the class. I have to Initialize the size of the array (the array is the class) to be the size passed Into the constructor below. I don’t know how to do that though. public ItemArray(int size) {}
2 Antworten
+ 12
In the main method
ItemArray obj = new ItemArray(/* pass your value */);
+ 3
Do you mean something like this?
public class ItemArray {
//your variable
int size;
//your constructor
public ItemArray(int size){
//this.size means your variable
//int size is the variable from outside
this.size = size;
}
}