Header Ads

  • Breaking Now

    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:

    1. Give me more information about interface

      ReplyDelete
    2. 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.

      ReplyDelete

    Post Top Ad

    Post Bottom Ad