作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
假设我得到了这个接口(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
了解 implements
和 extends
关键字之间的区别很重要。所以,我建议你开始阅读这个问题: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/
我是一名优秀的程序员,十分优秀!