Content deleted Content added
No edit summary Tag: Reverted |
PlanetJuice (talk | contribs) m Rollback edit(s) by 122.56.77.149 (talk): Vandalism (RW 16.1) |
||
Line 1:
An '''interface''' in the [[Java (programming language)|Java programming language]] is an [[abstract type]] that is used to describe a behavior that [[class (computer science)|classes]] must implement
Interfaces cannot be [[Instance (computer science)|instantiated]], but rather are implemented. A class that implements an interface must implement all of the non-default methods described in the interface, or be an [[abstract class]]. Object references in Java may be specified to be of an interface type; in each case, they must either be [[null pointer|null]], or be bound to an object that implements the interface.
Line 10:
Another use of interfaces is being able to use an [[Object (computer science)|object]] without knowing its type of class, but rather only that it implements a certain interface. For instance, if one were annoyed by a whistling noise, one may not know whether it is a human or a parrot, because all that could be determined is that a whistler is whistling. The call <code>whistler.whistle()</code> will call the implemented method <code>whistle</code> of object <code>whistler</code> no matter what class it has, provided it implements <code>Whistler</code>. In a more practical example, a [[sorting algorithm]] may expect an object of type {{Javadoc:SE|java/lang|Comparable}}. Thus, without knowing the specific type, it knows that objects of that type can somehow be sorted.
For example:
<syntaxhighlight lang="Java">
|