-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestStatic.java
More file actions
53 lines (42 loc) · 1.25 KB
/
TestStatic.java
File metadata and controls
53 lines (42 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package _Test;
public class TestStatic {
/**
* 程序执行了一次 new TestB() ,由于 TestB 类继承了 TestA 类,程序会先去执行 TestA 类的静态代码块,
* 然后执行 TestB 类的静态代码块,然后执行 TestA 类的构造代码块和构造方法,
* 最后执行 TestB 类的构造代码块和构造方法。
*/
static class A {
static {
System.out.println("A 静态块>>>>>");
}
{
System.out.println("A 构造块>>>>>");
}
A() {
System.out.println("A 无参构造方法>>>>>");
}
A(int a) {
System.out.println("A 有参构造方法>>>>>: " + a);
}
}
static class B extends A {
static {
System.out.println("B 静态块>>>>>");
}
{
System.out.println("B 构造块>>>>>");
}
B() {
System.out.println("B 无参构造方法>>>>>");
}
B(int a) {
// super(a);
System.out.println("B 有参构造方法>>>>>: " + a);
}
}
public static void main(String[] args) {
B test = new B();
System.out.println("+++++++++++++");
B test2 = new B(1);
}
}