I donā€™t understand how to initialize an array that is the class | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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) {}

1st Sep 2019, 7:36 PM
Jamie Charles
2 Respostas
+ 12
In the main method ItemArray obj = new ItemArray(/* pass your value */);
1st Sep 2019, 7:52 PM
Sumit ProgrammeršŸ˜ŽšŸ˜Ž
Sumit ProgrammeršŸ˜ŽšŸ˜Ž - avatar
+ 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; } }
1st Sep 2019, 7:54 PM
Denise RoƟberg
Denise RoƟberg - avatar