Select the code in which an ArrayIndexOutOfBoundsException occurs and is properly caught.
try { int intArray = new int[5]; arr[7] = 5; System.out.println(arr[7]); } finally { System.out.println("Finally Caught"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Caught"); }
try { int intArray = new int[5]; arr[7] = 5; System.out.println(arr[7]); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Caught"); } finally { System.out.println("Finally Caught"); }
int intArray = new int[5]; arr[7] = 5; System.out.println(arr[7]); catch (ArrayIndexOutOfBoundsException e) { System.out.println("Caught"); } finally { System.out.println("Finally Caught"); }
try { int intArray = new int[7]; arr[5] = 5; System.out.println(arr[7]); System.out.println("Finally Caught"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Caught"); }
Select the correct answer.
For those who aren't programmers, it's a trick question. I've highlighted in red the key to the trick.
The answer according to the test is B. The real answer is none of the above
. Their proofreaders missed the fact that the variable name used is incorrect. There will be no exception because it won't run in the first place, much less run and throw an exception.