相关疑难解决方法(0)

"B类不能是C的超级接口;超级接口必须是接口"错误

我们假设我有这个界面A:

interface A
{
    void doThis();
    String doThat();
}
Run Code Online (Sandbox Code Playgroud)

所以,我想要一些抽象类来实现方法doThis()而不是doThat()方法:

abstract class B implements A
{
    public void doThis()
    {
        System.out.println("do this and then "+ doThat());
    }

}

abstract class B2 implements A
{
    public void doThis()
    {
        System.out.println(doThat() + "and then do this");
    }
}
Run Code Online (Sandbox Code Playgroud)

当你最终决定在常规类中实现de doThat方法时会出现错误:

public class C implements B
{
    public String doThat()
    {
        return "do that";
    }
}
Run Code Online (Sandbox Code Playgroud)

这个课让我看到上面提到的错误:

"B类不能是C的超级接口;超级接口必须是接口"

如果这个类的层次结构有效或者我应该采取其他方式,那么现在任何人都可以吗?

java

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

java ×1