gpt4 book ai didi

java - "The type B cannot be a superinterface of C; a superinterface must be an interface"错误

转载 作者:搜寻专家 更新时间:2023-10-31 08:05:47 25 4
gpt4 key购买 nike

假设我得到了这个接口(interface) A:

interface A
{
void doThis();
String doThat();
}

所以,我想要一些抽象类来实现 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");
}
}

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

public class C implements B
{
public String doThat()
{
return "do that";
}
}

这门课让我犯了上述错误:

"The type B cannot be a superinterface of C; a superinterface must be an interface"

现在任何人都可以知道这个类的层次结构是否有效,或者我应该换一种方式吗?

最佳答案

你必须使用extends

public class C extends B

了解 implementsextends 关键字之间的区别很重要。所以,我建议你开始阅读这个问题:Implements vs extends: When to use? What's the difference?以及那里的答案。

关于java - "The type B cannot be a superinterface of C; a superinterface must be an interface"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10435103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com