接口
1.
接口是一种特殊的抽象类,这种抽象类中只包含常量和方法的声明,而没有变量和方法的实现。
2.
接口中的常量默认为
public static final
的;也只能是
public static final
的,
它们不能是
“
空白
final”
,但可初始化成非常数表达式。
3.
接口中只能定义抽象方法,而且这些方法默认为
public
的、也只能是
public
的;
4.
接口这样描述自己:
“
对于实现我的所有类,看起来都应该象我现在这个样子
”
。
多个无关的类可以实现同一个接口,
所以我们常把接口用于建立类和类之间的一个
“
协议
”
。
5.
使用
interface
关键字创建一个接口,接口可以是
“
友好的
”
或“
public
”的。
6.
类使用接口,要使用
implements
(实现)关键字。我们要表达的意思是
“
接口看起来就象那个样子,这儿是它具体的工作细节
”
。
一个类可以实现多个无关的接口,
所有接口名置于
implements
关键字的后面,并用逗号分隔它们。
7.
与继承关系类似,接口与实现类之间存在多态性
8.
接口可以多继承其它的接口,并添加新的属性和抽象方法。
9.
通过接口可以实现不相关类的相同行为,而不需要考虑这些类之间的层次关系。
10.
通过接口可以指明多个类需要实现的方法。
11.
通过接口可以了解对象的交互界面,而不需了解对象所对应的类。
分享到:
相关推荐
Java Methods-Class Hierarchies and Interfaces.ppt
Brain Computer Interfaces Fundamentals to Future Technologies
第五章 接口--Interfaces in Java 第六章 包--Concept of Packages 第七章 异常--Exception Handling in Java 第二部分包括: IO Streams in Java--IO系统 Threads--线程 Networking--网络编程 GUI programming ...
Matlab 7 - Creating Graphical User Interfaces
Matlab 7 - Creating Graphical User Interfaces
Functional Interfaces in Java Fundamentals and Examples. Java英文原版图书,2019年最新出版,清晰文字源生PDF,带目录标签。
java 霸王的大陆 源码 inc-overlord-common-interfaces Common BSD licensed Java interfaces.
plus Java developers with a basic all-in-one programming reference * Covers the recent release of the Java 2 Platform Standard Edition 5.0 and the new J2SE Development Kit 5.0 * Starts with ...
Audiovisual-Attentive-User-Interfaces-MIT-Media-.pptx
JAVA-V2-Interfaces-Comparable-y-Comparator
Human-in-the-Loop Machine Learning lays out methods for humans and machines to work together effectively. Summary Most machine learning systems that are deployed in the world today learn from human ...
java-master-class-innter-abstract-classes-interfaces 适用于软件开发人员的Java编程大师班(第9章:内部和抽象类与接口)
Volume I is designed to quickly bring you up to speed on what’s new in Java SE 6 and to help you make the transition as efficiently as possible, whether you’re upgrading from an earlier version of ...
java8流源码Java8-Functional-Interfaces-and-Lambda-Expressions 为什么使用 Lambda 启用函数式编程:我们可以将函数用作可以传递的实体。 可读且简洁的代码:强大的匿名内部类。 Lambda 使其可读且简洁。 更易于...
Big_problems_with_big_data_-_Hadoop_interfaces_security 云安全 大数据 工控安全 安全体系 安全众测
Java, Java, Java, Object-Oriented Problem Solving (3rd Edition) 3rd Edition by Ralph Morelli (Author), Ralph Walde (Author) 856 pages (June 25, 2017) 出版社: Prentice Hall; 3 edition Language: ...
javafx 比较好的学习资料 Learn JavaFX 8 - Building User Experience and Interfaces with Java 8 - 1st Edition (2015)
Java Graphical User Interfaces - An Introduction to Java Programming.pdf
This second edition has been updated to align with Java SE 8 and Java EE 7, and includes new information on GUI basics, lambda expressions, streaming API, WebSockets, and Gradle. Even if you have no ...