假设我有一个带字段的接口 - String type =“interface”。
它的实现类有一个字段 - String type =“class”
有没有办法通过该类访问界面的字段?
答案 0 :(得分:2)
是的..因为基本上接口变量是公共静态final或者换句话说是常量..
您可以使用
以静态方式访问它IYourInterfaceName.type
答案 1 :(得分: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();
}
}