Java - What is the output: Runtime Array Bounds Checks?

Question

What is the output of the following code?

int[] test = new int[3];
test[0] = 1;
test[3] = 7;


Click to view the answer

// index 3 is not between 0 and 2. At runtime, an exception is thrown.
test[3] = 7;

Note

At runtime, Java checks array bounds for every access to an array element.

If the array bounds are exceeded, an java.lang.ArrayIndexOutOfBoundsException is thrown.

Related Quiz