Java Interface

Java Interface

A Java interface is a collection of abstract methods and constant declarations.
Java interface contains abstract methods.
Java interface can not be instantiated.
A Java class can implement one or more interfaces.
An interface can extend another interface using new methods abstract.
The variables and methods of an interface are by default public.
The methods declared in an interface are implicitly abstract.
The variables of an interface are by default constants even if not declared with static and final.
The constants declared in an interface are static and final attributes.

To define a java interface uses keyword interface.
To implement an java interface uses keyword implements.

Interface example

public interface A1{
    void test1();
}

public interface A2{
    void test2();
}

public interface A3 extends A1, A2{
    void test1();
    void test2();
}

public class MyClass implements A3{
    public void test1(){
        System.out.println("Test1!");
    }
    
    public void test2(){
        System.out.println("Test2!");
    }
    
    public static void main(String args[]){  
        MyClass ob = new MyClass();  
        ob.test1();  
        ob.test2(); 
     }      
}