Page 1 of 1

About Question enthuware.ocpjp.i.v11.2.3228 :

Posted: Wed Feb 19, 2020 2:50 pm
by Deleted User 6318
Shouldn't this sentence be rewritten?
So for example, a[] [] [] [] = new int[4] [3] [3] [5]; is same as a[] [] [] [] = new int [4] [] [] [];
In fact, the effect of such created variables is different - the first one is initialized with nulls, and the second - with arrays.

Re: About Question enthuware.ocpjp.i.v11.2.3228 :

Posted: Wed Feb 19, 2020 5:55 pm
by admin
Actually, the type of the variables created in both are exactly the same and the objects referred to by the variables in both the cases are also exactly same i.e. in both the cases, a refers to an int array of arrays of arrays or arrays (which is what the explanation is trying to get at). The difference is in the way the two arrays are initialized. In case of new int [4] [] [] [], only the elements of the first dimention are iniliazed (to null), while in case of new int[4] [3] [3] [5]; all elements of all dimensions are initialized to non null arrays (or 0 in the last dimension.)

Explanation has now been enhanced to make this point clear.

thank you for your feedback!