Interface (Java): Difference between revisions

Content deleted Content added
m Reverted edits by 219.65.69.2 (talk): editing tests (HG) (3.3.2)
defination and some other piece of shit
Tags: references removed Visual edit
Line 1:
 
An '''interface''' in the [[Java (programming language)|Java programming language]] is an [[abstract type]] that is used to specify a behaviour that [[class (computer science)|classes]] must implement. They are similar to [[Protocol (object-oriented programming)|protocol]]s. Interfaces are declared using the <code>interface</code> [[Java keywords|keyword]], and may only contain [[method signature]] and constant declarations (variable declarations that are declared to be both <code>[[Static_variable#Static_Variables_as_Class_Variables|static]]</code> and <code>[[Final (Java)|final]]</code>). All methods of an Interface do not contain implementation (method bodies) as of all versions below Java 8. Starting with Java 8, <code>default</code> and <code>static</code> methods may have implementation in the <code>interface</code> definition.<ref>{{cite web|url=http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html|title=Default Methods}}</ref>
 
Interfaces cannot be [[Instance (computer science)|instantiated]], but rather are implemented. A class that implements an interface must implement all of the 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.