In fact, the effect of such created variables is different - the first one is initialized with nulls, and the second - with arrays.So for example, a[] [] [] [] = new int[4] [3] [3] [5]; is same as a[] [] [] [] = new int [4] [] [] [];
About Question enthuware.ocpjp.i.v11.2.3228 :
Moderators: Site Manager, fjwalraven
-
- Posts: 61
- Joined: Sat Feb 15, 2020 8:56 am
- Contact:
About Question enthuware.ocpjp.i.v11.2.3228 :
Shouldn't this sentence be rewritten?
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3228 :
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!
Explanation has now been enhanced to make this point clear.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 5 guests