Skip to main content

now from java 8 you can add default method in your interface, that method(default method in the interface) is present in all the classes that will implement it....

Ex :--

public class Java8Tester

{

public static void main(String args[])

public class Java8Tester {  public static void main(String args[]) {   Vehicle vehicle = new Car();   vehicle.print();   } 

}

interface Vehicle

{

} interface Vehicle {  default void print()   {     System.out.println("I am a vehicle!");    } 

static void blowHorn()

 static void blowHorn() {     System.out.println("Blowing horn!!!");    } } 

}

interface FourWheeler

{

interface FourWheeler {  default void print()  {     System.out.println("I am a four wheeler!");     } 

}

class Car implements Vehicle, FourWheeler

{

} class Car implements Vehicle, FourWheeler { public void print()  {     Vehicle.super.print();   FourWheeler.super.print();   Vehicle.blowHorn();   System.out.println("I am a car!");  } } 

}

}

now from java 8 you can add default method in your interface, that method(default method in the interface) is present in all the classes that will implement it....

Ex :--

public class Java8Tester

{

public static void main(String args[])

 { Vehicle vehicle = new Car(); vehicle.print(); } 

}

interface Vehicle

{

 default void print()  {    System.out.println("I am a vehicle!");   } 

static void blowHorn()

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

}

interface FourWheeler

{

 default void print()  {   System.out.println("I am a four wheeler!");   } 

}

class Car implements Vehicle, FourWheeler

{

public void print()  {    Vehicle.super.print(); FourWheeler.super.print(); Vehicle.blowHorn(); System.out.println("I am a car!"); 

}

}

now from java 8 you can add default method in your interface, that method(default method in the interface) is present in all the classes that will implement it....

Ex :--

public class Java8Tester {  public static void main(String args[]) {   Vehicle vehicle = new Car();   vehicle.print();   } } interface Vehicle {  default void print() {   System.out.println("I am a vehicle!");  }  static void blowHorn() {   System.out.println("Blowing horn!!!");  } } interface FourWheeler {  default void print() {   System.out.println("I am a four wheeler!");   } } class Car implements Vehicle, FourWheeler { public void print() {   Vehicle.super.print();   FourWheeler.super.print();   Vehicle.blowHorn();   System.out.println("I am a car!");  } } 
Source Link

now from java 8 you can add default method in your interface, that method(default method in the interface) is present in all the classes that will implement it....

Ex :--

public class Java8Tester

{

public static void main(String args[])

 { Vehicle vehicle = new Car(); vehicle.print(); } 

}

interface Vehicle

{

 default void print() { System.out.println("I am a vehicle!"); } 

static void blowHorn()

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

}

interface FourWheeler

{

 default void print() { System.out.println("I am a four wheeler!"); } 

}

class Car implements Vehicle, FourWheeler

{

public void print() { Vehicle.super.print(); FourWheeler.super.print(); Vehicle.blowHorn(); System.out.println("I am a car!"); 

}

}