0 votes
in JAVA by
How will you call a default method of an interface in a class?

1 Answer

0 votes
by
Using the super keyword along with the interface name.

interface Vehicle {

   default void print() {

      System.out.println("I am a vehicle!");

   }

}

class Car implements Vehicle {

   public void print() {

      Vehicle.super.print();                  

   }

}

17. How will you call a static method of an interface in a class?

Using the name of the interface.

interface Vehicle {

   static void blowHorn() {

      System.out.println("Blowing horn!!!");

   }

}

class Car implements Vehicle {

   public void print() {

      Vehicle.blowHorn();                  

   }

}
...