Java Interface

Java Interface

A Java interface is a collection of abstract methods and constant declarations.
A Java class can implement one or more interfaces.
An interface can extend another interface using new methods abstract.

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(); 
     }      
}