Which one is valid statement?
int[] x =new int[0]{};new int[2];int[] x=new int[][]{{1}}[0];int[][] x = new int[]{0}[0][0];int x= new int[2]{}[];
The correct answer is 3, and I can understand why it's not 1, 2 or 5, but I don't understand 3 or 4 mean.
You cannot specify both a length
0and an array initializer at the same time.It's not a statement. It would become a statement if it were assigned to something else, among other possibilities.
This declares and initializes a 1x1 2D array, with
1being its only element. Then, array access is used to immediately access the "row" at position 0, the only such "row", which is itself a 1-length 1D array, and that is assigned to a 1D array.There is a lot wrong here. A 1-length, 1D array is created, but there are two array accesses on it. You can only supply one, because it's a 1D array.
The extra
[]doesn't do anything and is invalid syntax. Even if they're removed, you can't assign anintarray to a scalarint. Also you can't specify a length and an array initializer{}at the same time.