问题
Lets say I have an interface with a field - String type = "interface".
It's implementing class has a field - String type = "class".
Is there any way to access the interface's field through that class anymore?
回答1:
Yep.. because basically interface variable are public static final or in other word, a constant..
you can access it in a static way using your
IYourInterfaceName.type
回答2:
public interface Firstone {
String type="interface";
}
public class Abc implements Firstone {
/**
* @param args
*/
String type="class";
void check(){
System.out.println("my class\t"+type);
System.out.println("my interface\t"+Firstone.type);
}
public static void main(String[] args) {
Abc a=new Abc();
a.check();
}
}
来源:https://stackoverflow.com/questions/9305364/accessing-interfaces-overridden-variable