The interface is similar to a class which is a collection of public static final variables (constants) and abstract methods.

The interface is a mechanism to achieve full abstraction in java. There can be only abstract methods in the interface.

It is used to achieve full abstraction and multiple inheritances in Java.


Why do we use Interface?
  • It is used to achieve full abstraction.
  • By using Interface, you can achieve multiple inheritances in java.
  • It can be used to achieve loose coupling.                                                                                                                                                                                                                                                                         

properties of Interface
  • It is implicitly abstract. So we no need to use the abstract keyword when declaring an interface.
  • Each method in an interface is also implicitly abstract, so the abstract keyword is not needed.
  • Methods in an interface are implicitly public.
  • All the data members of the interface are implicitly public static final.                                                                                                                                                                                                                    

How interface is similar to the class?

Whenever we compile any Interface program it generates a .class file. That means the bytecode of an interface appears in a

.class file.   


How interface is different from the class?
  • You can not instantiate an interface.
  • It does not contain any constructors.
  • All methods in an interface are abstract.
  • The interface can not contain instance fields. Interface only contains public static final variables.
  • The interface is can not be extended by a class; it is implemented by a class.
  • The interface can extend multiple interfaces. It means the interface support multiple inheritances                                                                                                                                                                                                                                                                                                                                                

    When we use abstract and when Interface

    If we do not know about any things about implementation just we have requirement specifications then we should

    go for Interface

    If we are talking about implementation but not completely (partially implemented) then we should go for abstract


    Rules for implementation interface
    • A class can implement more than one interface at a time.
    • A class can extend only one class, but implement many interfaces.
    • An interface can extend another interface, similarly to the way that a class can extend another class.                                                                                                                                                                                         
    Implementing Interfaces:

  • A class uses the implements keyword to implement an interface. The implements keyword appears in the class declaration
  • following the extends portion of the declaration.                    
    Example of Multiple Inheritance using interface
           

Program:

interface Developer { void disp(); } interface Manager { void show(); } class Employee implements Developer, Manager { public void disp() { System.out.println("Hello Good Morning"); } public void show() { System.out.println("How are you ?"); } public static void main(String args[]) { Employee obj=new Employee(); obj.disp(); obj.show(); } }

Output:

Hello Good Morning How are you ?

  • Progamming is what actually means ?
  • What is software development ?
  • How we categorized software development in different manner.
C Programming
C Plus Plus
Python
Java Development
Web Designing
Javascript
Mysql
Oracle
We cover all the programming concepts in various programming languages, this tutorials are very help full for bigener as well as Experience developer, for the ease of understanding we categorized programming in different manner likewise.