0
How will you call a default method of an interface in a class in Java8?

Open 1 Answers 26 Views Education

How will you call a default method of an interface in a class in Java8?

1 Answer

0
How will you call a default method of an interface in a class in Java8?

Using super keyword along with interface name.

interface Vehicle {

   default void print() {

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

   }

}

class Car implements Vehicle {

   public void print() {

      Vehicle.super.print();                  

   }

}
by (53.7k points)
...