1.public class Test{
2. public static void main(String[] args){
3. byte [][]big = new byte[7][7];
4. byte[][] b= new byte[2][1];
5. byte b3=5;
6. byte b2 [][][][]=new byte[2][3][1][2];
7. }// here!!
8.}
which of the answers could be insert in the line seven and still to permit of the code was compilated?(you have 4 correct answers)
a)b2[0][1] =b;//correct
b)b[0][0] =b3;//correct
c)b2[1][1][0] =b[0][0];//wrong ???
d)b2[1][2][0]=b;//wrong ???
e)b2[0][1][0][0]=b[0][0];//correct
f)b2[0][1]= big;//correct
Let's examine this one by one:
a)b2 is a 4-dimensional array(there are 4 brackets). With option a, it is trying to initialize b2[0][1] with b. In line number 4, you will see that b is a 2-dimensional array(there are 2 brackets). This means that b2[0][1] expects a 2-dimensional array to get completely initialized. If the initialization were changed to b2 = b, the code will not compile because it will state that b2 is a 4-dimensional array and expects a 4-dimensional array size. Hence, if it were changed to b2[0][1][2][0]=b3, then it would be a correcr initialization because all the dimensions were specified, it only needs a byte value to initialize the particular element. Same explanations for all the others.
If it's still a little vague to you, try to count the number of brackets(assuming the elements are not out of bounds). For example, int arr[] = new int[2]; int anotherarr[] = new int[3]; Then it is safe to initialize arr[] with arr = anotherarr regardless of size. Only the dimensions(brackets) are restricted.
I hope you understood my explanation. If you get this, you'll see that it's an easy topic. I got confused the first time I've read about this, too.