JavaSe

经常忘记 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");
    }
}

本文来自博客园,作者:咸瑜,转载请注明原文链接:https://www.cnblogs.com/bi-hu/p/14851946.html

原文地址:https://www.cnblogs.com/bi-hu/p/14851946.html