OCA Java SE 8 Mock Exam - OCA Mock Question 27


Which option, if used to replace /* INSERT CODE HERE */, will make the code print 1? (Select 1 option.)

try { 
    String[][] names = {{"AAA", "BBB"}, null, {"CCC"}}; 
    System.out.println (names[2][1].substring(0, 2)); 
catch (/*INSERT CODE HERE*/) { 
  1. IndexPositionException e
  2. NullPointerException e
  3. ArrayIndexOutOfBoundsException e
  4. ArrayOutOfBoundsException e




A and D are incorrect because the Java API doesn't define any exception classes with these names.

Here's a list of the array values that are initialized by the code in this question:

names[0][0] = "AAA" 
names[0][1] = "BBB" 
names[1] = null 
names[2][0] = "CCC" 

Array position [2][1] isn't defined, any attempt to access it will throw ArrayIndexOutOfBoundsException.