⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interface.html

📁 一些JAVA的小程序
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><html><head><title>What Is an Interface?</title><script language="JavaScript"><!-- hidefunction openWin(term) {  url="../../information/glossary.html#" + term;  myWin= window.open(url, "Glossary",              "width=400,height=150,scrollbars=yes,status=no,toolbar=no,menubar=no");  myWin.focus();}//--></script><STYLE type="text/css"><!--.FigureCaption   { margin-left: 1in; margin-right: 1in; font-family: Arial, Helvetica, sans-serif; font-size: smaller; text-align: justify }--></STYLE> </head><body BGCOLOR="#ffffff" LINK="#000099"><B><FONT SIZE="-1">The Java</font><sup><font size="-2">TM</font></sup> <font size="-1">Tutorial</FONT></B><br><table width="550" summary="layout"><tr><td align="left" valign="middle"><a href="inheritance.html" target="_top"><img src="../../images/PreviousArrow.gif" width="26" height="26" align="middle" border="0" alt="Previous Page"></a><a href="../TOC.html#concepts" target="_top"><img src="../../images/TOCIcon.gif" width="26" height="26" align="middle" border="0" alt="Lesson Contents"></a><a href="practical.html" target="_top"><img src="../../images/NextArrow.gif" width="26" height="26" align="middle" border="0" alt="Next Page"></a></td><td align="center" valign="middle"><font size="-1"><a href="../../index.html" target="_top">Start of Tutorial</a>&gt;<a href="../index.html" target="_top">Start of Trail</a>&gt;<a href="index.html" target="_top">Start of Lesson</a></font></td><td align="right" valign="middle"><font size="-1"><a href="../../search.html" target="_top">Search</a><br><a href="http://developer.sun.com/contact/tutorial_feedback.jsp">Feedback Form</a></font></td></tr></table><img src="../../images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" ALT=""><br><font size="-1"><b>Trail</b>: Learning the Java Language<br><b>Lesson</b>: Object-Oriented Programming Concepts</font><h2>What Is an Interface?</h2><blockquote>In general, an <em>interface</em> is a device or a system that unrelated entities use to interact. According to this definition, a remote control is an interface between you and a television set, the English language is an interface between two people, and the protocol of behavior enforced in the military is the interface between individuals of different ranks.<p>Within the Java programming language, an <a href="javascript:var meth=openWin; meth('interface');" onMouseOver="self.status='Look up interface in glossary'; return true;" onMouseOut="self.status=''; return true;"><font color="#00bb00"><em>interface</em></font></a><a href="javascript:var meth=openWin; meth('interface');" onMouseOver="self.status='Look up interface in glossary'; return true;" onMouseOut="self.status=''; return true;"><img src="../../images/glossaryIcon.gif" width=11 height=11 border=0 align="MIDDLE" alt=" (in the glossary)"></a> is a type, just as a class is a type.Like a class, an interface defines methods.Unlike a class, an interface never implements methods;instead, classes that implement the interfaceimplement the methods defined by the interface.A class can implement multiple interfaces.<p>The bicycle class and its class hierarchy define what a bicycle can and cannot do in terms of its "bicycleness." But bicycles interact with the world on other terms. For example, a bicycle in a store could be managed by an inventory program. An inventory program doesn't care what class of items it manages as long as each item provides certain information, such as price and tracking number. Instead of forcing class relationships on otherwise unrelated items, the inventory program sets up a communication protocol. This protocol comes in the form of a set of method definitions contained within an interface. The inventory interface would define, but not implement, methods that set and get the retail price, assign a tracking number, and so on.<P>To work in the inventory program, the bicycle class must agree to this protocol by implementing the interface. When a class implements an interface, the class agrees to implement all the methods defined in the interface. Thus, the bicycle class would provide the implementations for the methods that set and get retail price, assign a tracking number, and so on.<P>You use an interface to define a protocol of behavior that can be implemented by any class anywhere in the class hierarchy. Interfaces are useful for the following:<UL><LI>Capturing similarities among unrelated classes without artificially forcing a class relationship<LI>Declaring methods that one or more classes are expected to implement<LI>Revealing an object's programming interface without revealing its class<LI>Modeling multiple inheritance,a feature of some object-oriented languages that allows a class to have more than one superclass</UL></blockquote><img src="../../images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" ALT=""><br><table width="550" summary="layout"><tr><td align="left" valign="middle"><a href="inheritance.html" target="_top"><img src="../../images/PreviousArrow.gif" width="26" height="26" align="middle" border="0" alt="Previous Page"></a><a href="../TOC.html#concepts" target="_top"><img src="../../images/TOCIcon.gif" width="26" height="26" align="middle" border="0" alt="Lesson Contents"></a><a href="practical.html" target="_top"><img src="../../images/NextArrow.gif" width="26" height="26" align="middle" border="0" alt="Next Page"></a></td><td align="center" valign="middle"><font size="-1"><a href="../../index.html" target="_top">Start of Tutorial</a>&gt;<a href="../index.html" target="_top">Start of Trail</a>&gt;<a href="index.html" target="_top">Start of Lesson</a></font></td><td align="right" valign="middle"><font size="-1"><a href="../../search.html" target="_top">Search</a><br><a href="http://developer.sun.com/contact/tutorial_feedback.jsp">Feedback Form</a></font></td></tr></table><p><font size="-1"><a href="../../information/copyright.html">Copyright</a>1995-2005 Sun Microsystems, Inc.  All rights reserved.</font></p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -