“The type B cannot be a superinterface of C; a superinterface must be an interface” error
假设我得到了这个接口A:
| 12
 3
 4
 5
 
 | interface A
{
    void  doThis();
    String  doThat();
} | 
因此,我希望一些抽象类实现dothis()方法,而不是dothat()方法:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 
 | 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方法时,会出现错误:
| 12
 3
 4
 5
 6
 7
 
 | 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"
如果这个类层次结构是有效的,或者我应该反过来做,现在谁都可以了?
		
		
- 有关更多详细信息,我建议查看以下答案:stackoverflow.com/questions/10839131/…
 
	 
必须使用EDOCX1[0]
| 1
 | public class C extends B | 
理解implements和extends关键字之间的区别是很重要的。所以,我建议您从这个问题开始阅读:实现vs扩展:何时使用?有什么区别?答案就在这里。
		
		
- 谢谢!我还忘了将公共抽象字符串dothat()添加到每个抽象类:s
- @painyjames您不需要将public abstract String doThat()添加到每个抽象类中。
 
	 
由于B是一个类,正确的语法是使用extends:
| 1
 | public class C extends B { | 
B是抽象类,不能与"implements"关键字一起使用。你必须用"扩展"来代替。