为什么接口无法实现其他接口? [英] Why an interface can not implement another interface?
问题描述
我的意思是:
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
意图声明只提供时接口
不用于实现。
implements
means implementation, when interface
is meant to declare just to provide interface
not for implementation.
100%抽象类
在功能上等同于 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屋!