java java中接口和抽象接口的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10570894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 01:37:04  来源:igfitidea点击:

Difference between interface and abstract interface in java

javainterfaceabstract

提问by Brad

Like the title says. What is the difference between an interface and an abstract interface in Java?

正如标题所说。Java中的接口和抽象接口有什么区别?

回答by MByD

There is no such thing as abstract interface in Java (as interface is abstract by default), there is Abstract class.

Java中没有抽象接口这样的东西(因为接口默认是抽象的),有抽象类。

The main difference between an abstract class and an interface, is that abstract class is inherited (extended), as normal class, so you cannot extend two of them in parallel, while you can implement more than one interface at the same time.

抽象类和接口的主要区别在于,抽象类是继承(扩展)的,与普通类一样,不能并行扩展其中的两个,而可以同时实现多个接口。

回答by Frederik Wordenskjold

The abstract keyword is obsolete when working with Java interfaces, as a java interface by definition is abstract; it contains no implementation but only definitions.

使用 Java 接口时,abstract 关键字已过时,因为根据定义,java 接口是抽象的;它不包含实现,只包含定义。

回答by Devi Kiran

Interfaces are already abstract. Remember the key term "abstract" as it relates to OOP means that you can't create an instance of itself, you can only use it as a base class from which you can derive your own objects from it.

接口已经是抽象的。请记住与 OOP 相关的关键术语“抽象”意味着您不能创建其自身的实例,您只能将其用作基类,您可以从中派生出您自己的对象。

Interfaces by their very nature are abstract in that they don't define any code themselves, but must be implemented by classes which then provide the functionality of the methods in the interface.

接口本质上是抽象的,因为它们本身不定义任何代码,但必须由类实现,然后类提供接口中方法的功能。

So you can add the word "abstract" to the front of an interface and nothing will happen any differently. Even in the java documentation awhile back the writers made an error by including "abstract" in the wording for interfaces.

因此,您可以将“抽象”一词添加到界面的前面,而不会发生任何不同的情况。即使在前段时间的 Java 文档中,作者也犯了错误,在接口的措辞中包含“抽象”。

But you just need to know that all interfaces are abstract and there is no difference.

但是你只需要知道所有的接口都是抽象的,没有区别。

Check this link

检查此链接

回答by bouhmid_tun

An abstract class is a class which at least one method is not implemented. That's why it is mandatory to use the keyword "abstract" before writing the header of the method.

抽象类是至少没有实现一个方法的类。这就是为什么abstract在编写方法的标题之前必须使用关键字“ ”的原因。

Against by an interface is a class whose all methods are abstract, that's why it is not necessary to use the abstractkeyword.

接口所反对的是一个所有方法都是抽象的类,这就是为什么没有必要使用abstract关键字。