What is Interface in java?

Interface is a special class which is fully abstract.
By default all the variables declare in the interfaces must be treated as public and static and final.
By default all the methods will be treated as public and abstract.
Interface wouldn't allow method variables, constructor and concrete methods. We have to override abstract methods, we have to make a subclass abstract to implement interface.


If you will not assign variable as final static and method as public abstract then JVM by default make variable as final static variable and method as public abstract method.


NOTE:
  1. Interface contains only two type of members-a. public final static variable   b. public abstract method  
  2. Interface can't be instantiated but you can declare reference variable for the interface.
  3. When a subclass implements interface then it has to override all the abstract methods of interface otherwise subclass must be declare as abstract.
  4. When a class is implementing multiple interfaces which contain same variable then you can't access that variable directly you have to refer that common variable with interface name.          

2 comments :

  1. Pls edit :

    which contain same variable name then you can't access that variable directly

    ReplyDelete
  2. Thanks for your feedback and i have upadted...

    ReplyDelete