天天看點

代碼塊練習題:看代碼寫程式的執行結果。

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 }      
代碼塊練習題:看代碼寫程式的執行結果。

我的GitHub位址:

https://github.com/heizemingjun

我的部落格園位址:

http://www.cnblogs.com/chenmingjun

我的螞蟻筆記部落格位址:

http://blog.leanote.com/chenmingjun

Copyright ©2018 黑澤明軍

【轉載文章務必保留出處和署名,謝謝!】

繼續閱讀