package cn.hpu.test;
interface one{
static int x=11;
}
interface two{
final int x=22;
}
class Three{
public int x=33;
}
public class TestOne extends Three implements one ,two{
public void test() {
//System.out.println(x);此行出现错误提示
}
public static void main(String[] args) {
new TestOne().test();
}
}
如果父类的属性和接口中的常量出现重名问题,那么解决这类问题只能在TestOne测试类中重新声明一个重名变量了。
package cn.hpu.test;
interface one{
static int x=11;
}
interface two{
final int x=22;
}
class Three{
public int x=33;
}
public class TestOne extends Three implements one ,two{
int x=44;
public void test() {
System.out.println(x);
}
public static void main(String[] args) {
new TestOne().test();
}
}