0
arrays
why sometimes we put ...=new int[5] for exapmle and sometimes no!
1 Réponse
+ 4
int[] someArray = new int[5] - allocates an array in memory with 5 zero values and assign it to someArray pointer. After this allocation you can work with this array: write and read values.
If you write just int[] someArray; than you have only a pointer that is not initialized, and you can't use it in till you assign to it some array or null value. So you will need to initialize it later in the code.
Also if it is a field it will be initialized automatically with null value.