Tuesday, Jun 27th

Last update12:59:40 PM GMT


Write e-mail

Interfaces in Java


An interface is a pure abstract class, where each method is by default abstract. The user does need to specify the class or method with the keyword abstract, when the interface keyword is used for the class. Interface is a way to specify behaviour or role for the sub-classes. An interface can be declared using the keyword interface, can include only method declarations (that is, method names with return type and arguments specified) and constant declarations (that is, member variables which are static and final). An interface may never contain method definitions.

Since interfaces are implicitly abstract, they can’t be instantiated. But they can be instantiated indirectly by a class, which implements the said interface.  The class 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 which case, they must either be null, or be bound to an object that implements the interface.

Where classes don’t support multiple inheritance, interfaces simulate multiple inheritance. All classes in Java (except java.lang.Object) must have exactly one base class. Furthermore, a Java class may implement, and an interface may extend, any number of interfaces; however an interface may not implement an interface.

Share this post

Add comment

Please refrain from using slang or abusive language in the comments.
To avoid waiting for your comment to be published after being reviewed, please log in as a registered user.

Security code

Web Hosting