JavaSe - 基础 - 关于static代码块

时间:2021-06-05 18:04:20   收藏:0   阅读:0

经常忘记 static 代码块 反正如果你有调用(进入到) 他的类中他就执行
..  a.java:

public class a {
    public static void main(String[] args) {
        b.fun();
    }
}

b.java:

public class b {
    static {
        System.out.println("b");
    }

    public static void fun(){
        System.out.println("b  - static - fun");
    }
}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!