문제
다음 Java 프로그램의 실행 결과는?
Javapublic class Main { public static void main(String[] args) { try { String[] names = {"Java", "Python"}; System.out.print(names[3].length()); } catch (NullPointerException e) { System.out.print("NULL "); } catch (ArrayIndexOutOfBoundsException e) { System.out.print("INDEX "); } finally { try { int result = 10 / 0; } catch (ArithmeticException e) { System.out.print("MATH"); } } } }
① NULL MATH ② INDEX MATH ③ INDEX ④ 컴파일 오류
정답
2번
해설
names[3] 접근에서 ArrayIndexOutOfBoundsException이 발생하여 'INDEX '가 출력된다. finally 블록은 항상 실행되고, 내부의 10/0에서 ArithmeticException이 발생해 'MATH'가 출력된다.