CCTVCHCH
package com.ch.java1;

interface A {
    int x = 0;
}

class B {
    int x = 1;
}

class C extends B implements A {
    public void pX() {
        
        // System.out.println(x);//编译不通过。因为x是不明确的
        System.out.println(super.x);//1:父类的x
        System.out.println(A.x);//0:接口里的x是全局常量
        
    }

    public static void main(String[] args) {
        new C().pX();
    }
}

 

 

 

 

接口中的所有成员变量都默认是由public static final修饰的。
接口中的所有抽象方法都默认是由public abstract修饰的。

分类:

技术点:

相关文章:

  • 2021-09-30
  • 2021-09-30
  • 2021-09-30
  • 2021-09-30
  • 2021-04-23
猜你喜欢
  • 2021-11-09
  • 2021-04-18
相关资源
相似解决方案