免責事項:この記事はブロガーオリジナル記事です、続くBY-SAのCC 4.0を著作権契約、複製、元のソースのリンクと、この文を添付してください。
1.1初期化シーケンス、クラス
コンテンツの種類(静的変数、静的初期化ブロック)=>実施例コンテンツ(変数の初期化ブロック、コンストラクタ)
1.2、2つのクラス階層の初期化配列を有します
親クラス(静的変数、静的初期化ブロック)=>サブクラス(静的変数、静的初期化ブロック)=>親クラス(変数の初期化ブロック、コンストラクタ)=>サブクラス(変数の初期化ブロック、構成デバイス)
1 class A {
2 public A() {
3 System.out.println("Constructor A.");
4 }
5
6 {
7 System.out.println("Instance Block A.");
8 }
9 static {
10 System.out.println("Static Block A.");
11 }
12
13 public static void main(String[] args) {
14 new A();/*
15 * Static Block A. Instance Block A. Constructor A.
16 */
17 }
18 }
19
20 class B extends A {
21 public B() {
22 System.out.println("Constructor B.");
23 }
24
25 {
26 System.out.println("Instance Block B.");
27 }
28 static {
29 System.out.println("Static Block B.");
30 }
31
32 public static void main(String[] args) {
33 new A();/*
34 * Static Block A. Static Block B. Instance Block A. Constructor A.
35 */
36 System.out.println();
37 new B();/*
38 * Instance Block A. Constructor A. Instance Block B. Constructor B.
39 */// 静态成员和静态初始化块只会执行一次。
40 }
41 }