請寫出語句的執行結果:<br>code
HelloA.class<br>對象
public class HelloA { public HelloA() { System.out.println("HelloA"); } { System.out.println("I am HelloA class"); } static { System.out.println("static HelloA"); } }
HelloB.class<br>虛擬機
public class HelloB extends HelloA { public HelloB() { System.out.println("HelloB"); } { System.out.println("I am Hello B class"); } static { System.out.println("static HelloB"); } public static void main(String[] args){ System.out.println("----------main start ---------"); new HelloB(); new HelloB(); System.out.println("----------main end ------------"); } }
運行結果:<br>class
static HelloA static HelloB ----------main start --------- I am HelloA class HelloA I am Hello B class HelloB I am HelloA class HelloA I am Hello B class HelloB ----------main end ------------
解析:<br> Java 類在虛擬機中初始化的順序爲:<br>變量