相关疑难解决方法(0)

java继承的静态初始化

public class Main {

    public static void main(String[] args) {
        System.out.println(B.x);
    }

}
class A {
    public static String x = "x";
}
class B extends A {
    static {
        System.out.print("Inside B.");
    }
}
Run Code Online (Sandbox Code Playgroud)

问题:为什么输出将是:x.但不是:Inside B.x

java inheritance static static-initialization

17
推荐指数
2
解决办法
2906
查看次数

标签 统计

inheritance ×1

java ×1

static ×1

static-initialization ×1