java類加載時執行順序
阿新 • • 發佈:2018-02-04
width style new print 分享圖片 sta pub mage ati
源代碼 |
class HelloA { public HelloA() { System.out.print("A"); } { System.out.print("B"); } static { System.out.print("C"); } } public class HelloB extends HelloA { public HelloB() { System.out.print("D"); } { System.out.print("E"); } static { System.out.print("F"); } public static void main(String[] args) { System.out.print("G"); new HelloB(); new HelloB(); System.out.print("H"); } } 運行結果: |
圖解:
java類加載時執行順序