Monday, April 30, 2007

What is the use of interface?

An interface is a collection of public abstract methods and read only i.e. public, static and final variables.
The concept of interfaces in Java makes Multiple Inheritance a reality. Two or more non-related classes can implement the same interface. A class can implement multiple interfaces.Whenever there has to be an ancestry associated with classes along with some concrete behaviors then it is good idea to come up with abstract classes in such scenario but when implementation is more generic in nature and not dependent upon class relations or type hierarchy then such behaviors should be packaged inside an interface.The methods defined inside an interface can be implemented by non related classes.

3 comments :

Noushadjava on November 28, 2011 at 3:25 AM said...

Give more information

Unknown on November 28, 2011 at 3:27 AM said...

Give me more information about interface

Chatar on November 19, 2012 at 4:01 PM said...

Interface - is used to define type or contract of your api.

where as abstract class is used to put common functionality and does not define any concrete type.

 

Disclaimer
Interview Questions On Java,Java EE Copyright © 2017. Reads: best tracker