Which code snippets correctly create a two-dimensional array with 3 rows and 4 columns? (Select all that apply)
Trap 1: int[][] array = new int[3,4];
Incorrect. Java does not support comma-separated dimensions; it requires separate bracket pairs.
Trap 2: int array[][] = new int[3,4];
Incorrect. Like A, this uses a comma, which is not valid Java syntax.
- A
int[][] array = new int[3,4];
Why wrong: Incorrect. Java does not support comma-separated dimensions; it requires separate bracket pairs.
- B
int[] array[] = new int[3][4];
Correct. This uses a mixed declaration style where the array brackets are split between the type and the variable name, which is valid in Java.
- C
int array[][] = new int[3,4];
Why wrong: Incorrect. Like A, this uses a comma, which is not valid Java syntax.
- D
int[][] array = new int[3][4];
Correct. This is the standard syntax for declaring and initializing a two-dimensional array.