java初始化測試


public class TestClassInitial {
    public static void main(String[] args){
        Beetle b=new Beetle();
    }
}

class Insect{
    private int i=9;
    protected int j;
    Insect(){
        System.out.println("i="+i+", j="+j);
        j=39;
    }
    {
        System.out.println("  insect");

    }
    private static int x1=printStatic("static Insect.x1 init");
    static{
        System.out.println(" static insect");
    }
    public static int printStatic(String string) {
        // TODO Auto-generated method stub
        System.out.println(string);
        return 1;
    }
}
class Beetle extends Insect{
    private String k="k";
    static{
        System.out.println("static Beetle");
    }
    {
        System.out.println("Beetle");
    }
    public Beetle(){
        System.out.println("construct Beetle");
    }
    private static int x2=Insect.printStatic("beetle x2");
}
static Insect.x1 init
 static insect
static Beetle
beetle x2
  insect
i=9, j=0
Beetle
construct Beetle
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章