为什么接口无法实现其他接口?

编程入门 行业动态 更新时间:2024-10-23 16:14:50
本文介绍了为什么接口无法实现其他接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的意思是:

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.

更多推荐

为什么接口无法实现其他接口?

本文发布于:2023-06-07 15:23:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568565.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接口

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!