“B型不能是C的超接口;超级接口必须是一个接口“错误 [英] "The type B cannot be a superinterface of C; a superinterface must be an interface" error
问题描述
我们假设我有这个界面A:
Let's assume I got this interface A:
interface A
{
void doThis();
String doThat();
}
所以,我想要一些摘要类来实现方法doThis()但不是doThat()一:
So, I want some abstracts classes to implement the method doThis() but not the doThat() one:
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时出现错误常规类中的方法:
There error comes when you finally decide to implement de doThat method in a regular class:
public class C implements B
{
public String doThat()
{
return "do that";
}
}
这个课程让我看到上述错误:
This class leads me to the error aforementioned:
类型B不能是C的超接口;超级接口必须是接口
"The type B cannot be a superinterface of C; a superinterface must be an interface"
如果这个类的层次结构有效或者我应该采取其他方式吗?
Anyone could now if this hierarchy of classes is valid or should I do other way round?
推荐答案
您必须使用 extends
public class C extends B
了解工具
和扩展
关键字。所以,我建议你开始阅读这个问题: Implements vs extends :什么时候使用?有什么区别?和那里的答案。
Its important to understand the difference between the implements
and extends
Keywords. So, I recommend you start reading at this question: Implements vs extends: When to use? What's the difference? and the answers there.
这篇关于“B型不能是C的超接口;超级接口必须是一个接口“错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!