为什么一个接口不能实现另一个接口? [英] Why an interface can not implement another interface?

查看:38
本文介绍了为什么一个接口不能实现另一个接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是:

interface B {...}

interface A extends B {...} // allowed  

interface A implements B {...} // not allowed

我用谷歌搜索了一下,发现这个:

I googled it and I found this:

implements 表示定义接口方法的实现.但是接口没有实现,所以这是不可能的.

implements denotes defining an implementation for the methods of an interface. However interfaces have no implementation so that's not possible.

但是,接口是100%抽象类,抽象类可以实现接口(100%抽象类)而无需实现其方法.定义为接口"时有什么问题?

However, interface is an 100% abstract class, and an abstract class can implement interfaces (100% abstract class) without implement its methods. What is the problem when it is defining as "interface" ?

详细来说,

interface A {
    void methodA();
}

abstract class B implements A {} // we may not implement methodA() but allowed

class C extends B {
   void methodA(){}
} 

interface B implements A {} // not allowed. 
//however, interface B = %100 abstract class B

推荐答案

implements 表示实现,当 interface 表示只是为了提供 interface 不用于实现.

implements means implementation, when interface is meant to declare just to provide interface not for implementation.

100% abstract class 在功能上等同于 interface 但如果你愿意,它也可以有实现(在这种情况下,它不会保持 100% abstract),所以从 JVM 的角度来看,它们是不同的东西.

A 100% abstract class is functionally equivalent to an interface but it can also have implementation if you wish (in this case it won't remain 100% abstract), so from the JVM's perspective they are different things.

此外,100% 抽象类中的成员变量可以具有任何访问限定符,在接口中它们是隐式的public static final.

Also the member variable in a 100% abstract class can have any access qualifier, where in an interface they are implicitly public static final.

这篇关于为什么一个接口不能实现另一个接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆