JVM 接口初始化规则

一、建立两个接口,MyParent5接口,MyChild5 接口继承自MyParent5接口java

public class MyTest5 {

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

interface MyParent5{

    public static final int a = 5;

}

interface MyChild5 extends MyParent5{
    public static final int b = 6;

}

  接口成员变量默认为:public static finalblog

 

 打印结果继承

6

 

一、删除MyParent5.class 程序仍是能正常运行。接口

 二、接着讲MyChild5.class 程序仍是能正常运行  class

总结: 当一个接口在初始化时,并不要求其父类接口都完成了初始化。 变量

只有在真正使用父接口的时候(如引用接口中所定义的常量时),才会初始化。引用

相关文章
相关标签/搜索