Java출력 결과어려움 · 30점#상속#오버라이딩#생성자#필드 숨김

4. 생성자에서 호출한 오버라이딩 메서드

다음 Java 프로그램의 실행 결과를 쓰시오.

1class Parent {
2 int x = 10;
3
4 Parent() {
5 show();
6 }
7
8 void show() {
9 System.out.println("P" + x);
10 }
11}
12
13class Child extends Parent {
14 int x = 20;
15
16 Child() {
17 super();
18 show();
19 }
20
21 void show() {
22 System.out.println("C" + x);
23 }
24}
25
26public class Main {
27 public static void main(String[] args) {
28 Parent p = new Child();
29 System.out.println(p.x);
30 }
31}

해설을 먼저 보면 이후 정답 시 점수가 50%만 반영됩니다.