Originally posted by Lucky J Verma:
...But ,in this website http://www.go4expert.com/forums/showthread.php?t=1162
some other way to count objects is given...
That webpage has an error. The explanation seems correct, but the total is wrong. Where it says...
int[][] a2 = new int[10][5]; ...
This actually allocates 6 objects: a one-dimensional array of 5 elements for each of the rows, and a one-dimensional array of ten elements, with each element pointing to the appropriate row array.
...it
should say something like...
This actually allocates 11 objects: a one-dimensional array of 5 elements (the ints) for each of the ten rows (so that's ten one-dimensional arrays, each containing 5 ints); and a one-dimensional array of ten elements, with each element pointing to the appropriate row array.
This can be demonstrated with the following code. It creates an int[10][5], then iterates through to print each element. The ints print as default zeros. The array objects print as [I@xxxxxx, where "[I" indicates an int array, and "xxxxxx" represents the memory address. You will see from the output that there are 11 array objects.