The interface is like a class. The methods that interface are abstract and their scope is public. No object of the interface can be created, but a reference variable can be created. Methods are only declared in the interface.When the instance variable is initialized in the interface, it is by default compiler with public static final keywords.The Implement keyword is used through the class to implement the interface.Interfaces do not include constructors.Complete example for Why to use interface in Java? When an interface is used in a program, a rule of abstraction method is applied.

For example,

Why to use interface in Java; In the program, interface A has a method name (). It is accompanied by sub-public and abstract keywords. When a method is declared on an interface, it is necessary to place its body on its subclass.Relationship between class and interface.The extended keyword is used in interface and interface. The Implement keyword is used in the interface and class.

Example:Source Code :


interface A


    void disp1();



interface B extends A{


    void disp2();


class C implements B{


            public void disp1(){

                           System.out.println(“interface A”);


            public void disp2(){

                           System.out.println(“interface B”);



    public static void main(String args[])


     C obj = new C();

     obj.disp1 ();

            obj.disp2 ();




Some Why to use interface in Java rules are-An object of the interface cannot be created, but a reference variable can be created.The interface does not have a constructor.Interface and interface are enhanced.The interface and class are implemented.Each reference variable in the interface is with the public, static, and final keywords.Every instance variable in the interface; The constant is constant with the last keyword.Interface methods are public and abstract.