SEARCH BY

All

  • All
  • Java8
  • Spring

java8 default methods

Post a Comment
Default methods are new feature in java8 which allows to provide implementation for methods in interfaces declarations.

public interface Food{

default void menuItems(){


// write the code of this method implementation
 System.out.println("I am menu");

}

} // End of Food Class


public class Hotel implements Food{

// remember there is no overriding of method menuItems() of Food interface
public void hotelDetails(){

 System.out.println("I am Hotel Grand");
}

} // End of Hotel Class


public class Test
{

public static void main(String a[]){

Hotel h= new Hotel();
h.hotelDetails();
h.menuItems();

}
} // end of Test Class



jaya
I love software designing, coding, writing and teaching...

Share this article

Related Posts

Post a Comment

Place your code in <em> </em> tags to send in comments | Do not add hyper links in commnet

Close

Subscribe our newsletter for the latest articles directly into your email inbox