SQLD프로그래밍 언어 활용난이도 3MCQ

SQLD 프로그래밍 언어 활용 기출문제 #2438

문제

다음 Java 프로그램의 실행 결과는?

Java
public 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'가 출력된다.

이런 문제 20~50개를 한 번에 풀어보세요

매번 새로 추가되는 모의고사 + 오답 자동 복습 + 회차별 실력 추적. 회원가입 후 무료 이용.

[SQLD] 프로그래밍 언어 활용 기출 #2438 | sqldpass