프로그래밍 언어 활용난도 중상
20번 · 주관식 · 5점
다음 Java 프로그램에서 부모와 자식에 같은 이름으로 선언된 필드가 각각 어떻게 사용되는지 추적하여 출력 결과를 쓰시오.
class Base {
int score = 5;
Base() {
score += 2;
}
int total() {
return score * 2;
}
}
class Derived extends Base {
int score = 40;
Derived() {
score += 3;
}
int combined() {
return super.score + score;
}
}
public class Main {
public static void main(String[] args) {
Derived item = new Derived();
Base view = item;
System.out.print(item.combined() + ":" + view.total());
}
}