Java 8中接口和抽象类之间的根本区别 [英] Fundamental difference between interface and abstract class in Java 8

查看:169
本文介绍了Java 8中接口和抽象类之间的根本区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到接口现在可以为它提供的方法提供实现,我无法正确理解接口和抽象类之间的区别。有谁知道如何正确解释差异?

Considering that interfaces now can give an implementation to the methods it provides, I cannot properly rationalize the difference between interfaces and abstract classes. Does anyone know how to explain the difference properly?

我还被告知,与抽象类相比,接口稍微轻一些,性能明智。有人可以确认吗?

I was also told that interfaces are somewhat more light-weight compared to abstract classes, performance wise. Can someone confirm this?

推荐答案

接口仍然没有任何状态。接口仍然没有任何最终方法,这意味着任何实现都可以覆盖其所有默认方法。并且接口仍然不能有任何构造函数。

Interfaces still can't have any state. Interfaces still can't have any final method, which means that any implementation can override all its default methods. And interfaces still can't have any constructor.

您仍然可以实现多个接口,即使它们具有相同签名的默认方法。你不能扩展多个类(抽象或不抽象)。

You can still implement multiple interfaces, even if they have default methods with the same signature. You can't extend multiple classes (abstract or not).

这篇关于Java 8中接口和抽象类之间的根本区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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