gpt4 book ai didi

java - 接口(interface)的所有方法都是抽象的吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:59:45 25 4
gpt4 key购买 nike

我看到它写在大多数地方-

"All of the methods in an interface are abstract."

但是接口(interface)也可能包含默认方法静态方法,并且存在默认方法和静态方法的方法体。

那么接口(interface)的所有方法都是抽象的吗?

最佳答案

从 Java 8 开始,接口(interface)还可以包含默认方法和静态方法以及抽象方法。存在默认方法和静态方法的方法体。

One of the biggest design change in Java 8 is with the concept of interfaces. Prior to Java 7, we could have only method declarations in the interfaces. But from Java 8, we can have default methods and static methods in the interfaces.

Interface Default Method

For creating a default method in the interface, we need to use “default” keyword with the method signature.

Interface static methods

Static methods are similar to default methods except that we can’t override them in the implementation classes. This feature helps us in avoiding undesired results incase of poor implementation in child classes.

更多信息请查看this

关于java - 接口(interface)的所有方法都是抽象的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34973731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com