0
What is legal declaration of array in the following and explain why?and also explain why not others?
int a[][]=new int[4][4]; int[] a[]=new int[4][4]; int a[][]=new int[][4]; int[] a[]=new int[4][];
1 Answer
+ 7
An OCA question.
All of them are legal except for the third one.
int a[][] = new int[][4];
The dimensions must be created from left to right. The compiler cannot possibly allocate 4 slots of int to an arbitrary number of int[].
int[] a[] is simply equivalent to int[][] a and int a[][].