1 class HelloA { 2 3 public HelloA() { 4 System.out.println("HelloA"); 5 } 6 7 { System.out.println("I‘m A class"); } 8 9 static { System.out.println("static A"); } 10 11 } 12 13 public class HelloB extends HelloA { 14 public HelloB() { 15 System.out.println("HelloB"); 16 } 17 18 { System.out.println("I‘m B class"); } 19 20 static { System.out.println("static B"); } 21 22 public static void main(String[] args) { 23 24 System.out.println("-------main start-------"); 25 new HelloB(); 26 new HelloB(); 27 System.out.println("-------main end-------"); 28 } 29 }
Microsoft Windows [版本 6.2.9200]
(c) 2012 Microsoft Corporation。保留所有权利。
C:\Users\xw>javac HelloB.java
C:\Users\xw>java HelloB
static A
static B
-------main start-------
I‘m A class
HelloA
I‘m B class
HelloB
I‘m A class
HelloA
I‘m B class
HelloB
-------main end-------
时间: 2024-10-12 19:54:04