jvm虚拟机

  1. 类的加载连接和初始化

            验证问题:①对于静态字段来讲,只有直接定义了该字段的类才会被初始化;class

                             ②当一个类在初始化时,要求其父类都已经初始化完毕了static

            验证代码:co

            

public class MyTest1 {
    public static void main(String[] args) {
        System.out.println(MyChild1.str2);
    }
}

class MyParent1{
    public static String str= "hello world";

    static {
        System.out.println("Myparent1 static block");
    }
}

class MyChild1 extends MyParent1{

    public static String str2 = "welcome";
    static {
        System.out.println("MyChild1 static block");
    }
}
相关文章
相关标签/搜索