接口的所有方法都是抽象的吗? [英] Are all methods of interface abstract?

查看:32
本文介绍了接口的所有方法都是抽象的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I see its written in most places-

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

但是一个接口也可能包含默认方法静态方法,并且存在默认方法和静态方法的方法体.

But an interface may also contain default methods and static methods and method bodies exists for default methods and static methods.

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

so are all methods of interface abstract?

推荐答案

从 Java 8 开始,接口还可以包含默认方法和静态方法以及抽象方法.默认方法和静态方法都存在方法体.

From Java 8, an interface may also contain default methods and static methods along with abstract methods . Method bodies exist for default and static methods.

Java 8 中最大的设计变化之一是接口.在 Java 7 之前,我们只能在接口.但是从 Java 8 开始,我们可以有默认方法和接口中的静态方法.

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.

接口默认方法

为了在接口中创建默认方法,我们需要使用带有方法签名的default"关键字.

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

接口静态方法

静态方法类似于默认方法,只是我们不能在实现类中覆盖它们.此功能可帮助我们避免在儿童执行不力的情况下产生不希望的结果类.

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.

有关更多信息,请查看 这个

For more check out this

这篇关于接口的所有方法都是抽象的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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