纯属复制粘贴,人家整理的太好了
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.运行结果
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 new HelloB(); 24 }25 26 }
21.
22.
23.
24.
25.
26.
27.
28.