• 코드:
​x
 
1
class InitBlock {
2
    static int classVar;                        // 클래스 변수
3
    int instanceVar;                            // 인스턴스 변수
4
    static {                                    // 클래스 초기화 블록을 이용한 초기화
5
        classVar = 10;
6
    }
7
}
8
​
9
public class prog {
10
    public static void main(String[] args) {
11
        System.out.println(InitBlock.classVar); // 클래스 변수에 접근
12
    }
13
}
표준입력 & 실행옵션