Java_静态代码块作用

 1 /*
 2 静态代码块
 3 
 4 1,随着类的加载而执行,而且只执行一次
 5 2,优先于主函数执行。
 6 
 7 作用:给类进行初始化
 8 */
 9 class StaticCode
10 {
11     static //静态代码块
12     {
13         System.out.println("A");
14     }
15     public void show()
16     {
17         System.out.println("show run");
18     }
19 }
20 
21 class StaticCodeDemo
22 {
23     static
24     {
25         System.out.println("b");
26     }
27      
28 
29     public static void main(String[] args) 
30     {
31         new StaticCode().show();
32         
33     }
34     static 
35     {
36         System.out.println("C");
37     }
38 }

 

posted @ 2017-11-16 16:21  BirdieForLove  阅读(316)  评论(0编辑  收藏  举报