top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

what is the role of interface in java?

+1 vote
553 views

use of interface.

posted Jul 12, 2013 by Dheerendra Dwivedi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

An interface in the Java programming language is an abstract type that is used to specify an interface (in the generic sense of the term) that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations (variable declarations that are declared to be both static and final). An interface may never contain method definitions.
Interfaces cannot be 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 which case, they must either be null, or be bound to an object that implements the interface.
One benefit of using interfaces is that they simulate multiple inheritance. All classes in Java must have exactly one base class, the only exception being java.lang.Object (the root class of the Java type system); multiple inheritance of classes is not allowed.
A Java class may implement, and an interface may extend, any number of interfaces; however an interface may not implement an interface.

Source: http://en.wikipedia.org/wiki/Interface_%28Java%29 (for more detail check this link).

answer Jul 12, 2013 by Mithalesh Gupta
0 votes

You can achieve polymorphism using Interfaces.

I found a useful tutorial explaining importance of Interfaces in java.
Check this out -

answer Jul 12, 2013 by Sudheendra
...