Below is the program. But please clarify for me the line in the subject?
It the new Food() selectable object part of Selectable interface? I thought you can't instantiate an interface?
public class Solution {
public static void main(String[] args) {
Food food = new Food();
Selectable selectable = new Food();
Food newFood = (Food) selectable;
foodMethods(food);
selectableMethods(selectable);
}
public static void foodMethods(Food food) {
//write your code here
food.onSelect();
food.onEat();
}
public static void selectableMethods(Selectable selectable) {
//write your code here
selectable.onSelect();
}
interface Selectable {
void onSelect();
}
static class Food implements Selectable {
public void onEat() {
System.out.println("The food was eaten");
}
public void onSelect(){
System.out.println("The food was selected");
}
}
}