Which of the following code gives error of “out of bounds” in array?

RPSC Programmer 2024

Which of the following code gives error of “out of bounds” in array?

  1. A.

    int[] a = new int[5];
    a[4] = 5;

  2. B.

    int[] a = {1, 2, 3, 4, 5};
    System.out.print(a[2]);

  3. C.

    int[] a = new int[10];
    for (int i = 0; i < a.length; i++) {
    a[i] = i * 2;
    }

  4. D.

    int[] a = new int[3];
    a[3] = 9;

  5. E.

    Question not attempted

Attempted by 372 students.

Sign up free to check your answer

Sign up free

Explore the full course: Isro

Loading lesson…