It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                7年前关闭。
            
        

假设我有2个接口

interface A {

    public static final int CONSTANT1 = 6;

}

interface B {

    public static final int CONSTANT1 = 7;
}

class MYclass implements A, B {

    public static void main(String[] args) {

        System.out.println(CONSTANT1);//<- ??

    }
}


将打印哪个常数,还是编译错误?

最佳答案

只是作为参考,代码如下:

interface A
{
    int CONSTANT1 = 6;
}

interface B
{
    int CONSTANT1 = 7;
}

public class Test implements A, B
{
    public static void main(String[] args)
    {
        System.out.println(CONSTANT1);
    }
}


打印7。

08-06 06:15