前言:
直接给一个实例
1.创建Class C,如下:
interface A{
String s = "A";
}
class B{
String s= "B";
}
class C extends B implements A {
public static void main(String [] args){
C c= new C();
c.getStringValue();
}
public void getStringValue(){
System.out.println(s);
}
}
2.上述Class C中,运行程序会直接报错,其原因是 getStringValue 函数打印s时不清楚来源
3.如果访问接口的s,需要:
public void getStringValue(){
System.out.println(A.s);
}
4.如果访问父类的s,需要
public void getStringValue(){
System.out.println(super.s);
}
5.经测试该方案可行。