1. Which of these statements are legal. Select the three correct answers.
  1. a. int arr[][] = new int[5][5];

  2. b. int []arr[] = new int[5][5];

  3. c. int[][] arr = new int[5][5];

  4. d. int[] arr = new int[5][];

  5. e. int[] arr = new int[][5];


Correct Option: A,B

AI Explanation

To answer this question, we need to understand the syntax for creating multidimensional arrays in Java.

Option A) int arr[][] = new int[5][5]; - This option is correct. It declares and initializes a two-dimensional array arr with dimensions 5x5.

Option B) int []arr[] = new int[5][5]; - This option is correct. It declares and initializes a two-dimensional array arr with dimensions 5x5. It uses a different syntax to declare the array, but it is still legal.

Option C) int[][] arr = new int[5][5]; - This option is correct. It declares and initializes a two-dimensional array arr with dimensions 5x5. It uses the common syntax for declaring arrays.

Option D) int[] arr = new int[5][]; - This option is incorrect. It declares and initializes a one-dimensional array arr with a length of 5, but the second dimension is left unspecified.

Option E) int[] arr = new int[][5]; - This option is incorrect. It tries to declare a one-dimensional array arr with an unspecified length for the first dimension and a length of 5 for the second dimension, which is not allowed.

The correct answers are A, B, and C.

Find more quizzes: