代码块练习题:看代码写程序的执行结果。

 1 /*
 2     代码块练习题:
 3         看代码写程序的执行结果。
 4     
 5     输出结果是:
 6         林青霞都60了,我很伤心
 7         我是main方法
 8         Student 静态代码块
 9         Student 构造代码块
10         Student 构造方法
11         Student 构造代码块
12         Student 构造方法
13 */
14 
15 class Student {
16     static {
17         System.out.println("Student 静态代码块");
18     }
19     
20     {
21         System.out.println("Student 构造代码块");
22     }
23     
24     public Student() {
25         System.out.println("Student 构造方法");
26     }
27 }
28 
29 class StudentDemo {
30     static {
31         System.out.println("林青霞都60了,我很伤心");
32     }
33     
34     public static void main(String[] args) {
35         System.out.println("我是main方法");
36         
37         Student s1 = new Student();
38         Student s2 = new Student();
39     }
40 }

原文地址:https://www.cnblogs.com/chenmingjun/p/8448996.html