in Education by (55.8k points)

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

1 Answer

0 votes
by (55.8k points)
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();                  

   }

}

Related questions

0 votes
asked Nov 8, 2020 in Education by Editorial Staff (55.8k points)
0 votes
asked Feb 12 in Education by JackTerrance (1.9m points)
...