java Java接口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/416331/
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-29 12:17:57  来源:igfitidea点击:

Java Interfaces?

javaoop

回答by Click Upvote

What is an Interface?from Java's official tutorial

什么是接口?来自Java的官方教程

Edit: A second resource from the same tutorial, is the Interfaces and Inheritencesection.

编辑:来自同一教程的第二个资源是接口和继承部分。

回答by Toon Krijthe

In general:

一般来说:

You can see an interface as a contract or an agreement between two parties. So they can develop independently as long as the interface does not change.

您可以将接口视为两方之间的合同或协议。所以只要接口不变,他们就可以独立开发。

The calling party, knows which behaviour is available and the implementing party knows what to implement.

调用方知道哪些行为可用,执行方知道要实现什么。

There are a lot of advantages by using interfaces. One of them is that it is easy to switch between implementations. The other one is that classes can have different (inter)faces without using multiple inheritance.

使用接口有很多好处。其中之一是很容易在实现之间切换。另一个是类可以在不使用多重继承的情况下具有不同的(接口)接口。

回答by WiseTechi

You might want to have a look at this excellent book by Bruce Eckel (free available in electronic format) : Thinking in Java

你可能想看看 Bruce Eckel 的这本优秀的书(电子版免费提供): Thinking in Java

回答by Yasir Shabbir Choudhary

Interface is just like Java class but it contain only abstract method and final attribute.Basically interface are used to achieve "Polymorphic" behavior.

接口就像Java类,但它只包含抽象方法和最终属性。接口基本上是用来实现“多态”行为的。

Here is the detail coding example

这是详细的编码示例