• 코드:
​x
 
1
class Parent {
2
    private int a = 10;     // private 필드
3
    public int b = 20;      // public 필드
4
}
5
​
6
class Child extends Parent {
7
    public int c = 30;      // public 필드
8
    void display() {
9
        // System.out.println(a);   // 상속받은 private 필드 참조
10
        System.out.println(b);      // 상속받은 public 필드 참조
11
        System.out.println(c);      // 자식 클래스에서 선언한 public 필드 참조
12
    }
13
}
14
​
15
public class prog {
16
    public static void main(String[] args) {
17
        Child ch = new Child();
18
        ch.display();
19
    }
20
}
표준입력 & 실행옵션