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

Posted by: jaya
Post a Comment
Post a Comment