by Dinesh Thakur

A class can implement more than one interface. For this, you write the names of all interfaces that the class implement separated by commas following the implements keyword and the class body must provide implementations for all of the methods specified in the interfaces. The syntax for implementing multiple interfaces is

[public] class className [ extends superClassName]

implements interfacel, interface2, interfaceN

{

// Provide implementation for methods of

// all included interfaces .

In order to understand this let us consider an Example.

interface Interface1

{
    void f1();
}
//Interface two
 interface Interface2
{
     void f2();
}
class X implements Interface1,Interface2
{
       //definition of method declared in interfacel
        public void f1()
        {
             System.out.println("Contens of Method f1()in Interface1");
         }
     
        // definition of method declared in interface2
        public void f2()
        {
              System.out.println("Contens of Method f2()in Interface2") ;
        }
      
        public void f3()
        {
              System.out.println("Contens of Method f3() of Class X");
         }
}
      class MultipleInterface
{
        public static void main(String[] args)
      {
          Interface1 vl ; //Reference variable of Interfacel
          vl = new X();   //assign object of class x
          vl.f1();
          Interface2 v2; //Reference variable of Interface2
          v2 = new X();   //assign object of class x
          v2.f2();
          X xl=new X();
          xl.f3();
     }
}

Multiple Interfaces in Java with Example