??????1.加載基類,初始化基類中的靜態成員變量。

????? 2.加載派生類,初始化派生類中的靜態成員變量。

????? 3.運行派生類的main方法。

????? 4.初始化基類中的其他成員變量(static類型的除外)。

????? 5.調用基類構造函數。

????? 6.初始化派生類中的其他成員變量(static類型的除外)。

????? 7.調用派生類構造函數。

for example:

Beetle.java

class Insect {
??? private int i = 9;
??? private int l = print("Insect.l initialized");
??? protected int j ;
??? public Insect(){
??????? System.out.println("i="+i+" j="+j);
??????? j = 39;
??? }
??? private static int x1 = print("static Insect.x1 initialized");
??? static int print(String s){
??????? System.out.println(s);
??????? return 47;
??? }
}
public class Beetle extends Insect{

??? private int k = print("Beetle.k initialized");
??? //private int j=100;

??? public Beetle(){
??????? System.out.println("k = "+k);
??????? System.out.println("j = "+j);
??? }
??? private static int y = print("Beetle.y initialized");
??? public static void main(String[] args) {
??????? System.out.println("Beetle constructor");
??????? Beetle b = new Beetle();
??????? //Insect i = new Insect();
??? }

}

運行輸出:

static Insect.x1 initialized
Beetle.y initialized
Beetle constructor
Insect.l initialized
i=9 j=0
Beetle.k initialized
k = 47
j = 39