Java OCA OCP Practice Question 1660

Question

Which of these array declaration statements are not legal?.

Select the two correct answers.

  • (a) int[] i[] = { { 1, 2 }, { 1 }, {}, { 1, 2, 3 } };
  • (b) int i[] = new int[2] {1, 2};
  • (c) int i[][] = new int[][] { {1, 2, 3}, {4, 5, 6} };
  • (d) int i[][] = { { 1, 2 }, new int[ 2 ] };
  • (e) int i[4] = { 1, 2, 3, 4 };


(b) and (e)

Note

The size of the array cannot be specified, as in (b) and (e).

The size of the array is given implicitly by the initialization code.

The size of the array is never specified in the declaration of an array reference.

The size of an array is always associated with the array instance (on the right-hand side), not the array reference (on the left-hand side).




PreviousNext

Related