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

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

문제

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

interface Drawable { void draw(); default void display() { System.out.print("Interface "); } } class Rectangle implements Drawable { public void draw() { System.out.print("Rectangle "); } public void display() { System.out.print("Custom "); } } public class Main { public static void main(String[] args) { Drawable d = new Rectangle(); d.display(); d.draw(); } }

① Interface Rectangle ② Custom Rectangle ③ 컴파일 오류 (인터페이스 메서드 재정의 불가) ④ Interface Custom

정답

2

해설

인터페이스의 default 메서드는 구현 클래스에서 재정의할 수 있다. Rectangle 클래스에서 display()를 재정의했으므로 "Custom "이 출력되고, draw() 메서드 구현에 의해 "Rectangle "이 출력된다.

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

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

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