A

Admin • 825.56K Points
Coach

Q. Which of the following arrays will throw an exception when accessed?

  • (A) int[] a = new int[0]; a[0];
  • (B) int[] a = new int[2]; a[1];
  • (C) int[] a = {1, 2}; a[2];
  • (D) int[] a = new int[]{1}; a[0];

Explanation by: Admin
Index 2 does not exist in an array of size 2 (index 0 and 1 only).

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.