import java.util.*; public class FoodExample { public static void main(String[] args){ Animal a; Omniwore o; Tiger t; List< Animal > lo = new ArrayList>(); //List lo = new ArrayList(); //List lo = new ArrayList(); t = new Tiger(); a=t; a.feed(new Food()); lo.add(t); lo.get(0).feed(new Meat() ); //t.feed(new Food()); // compile time error t.feed(new Meat()); //t.feed(new Grass());// compile time error // o = t; // compile time error o = new Omniwore(); o.feed(new Food()); o.feed(new Meat()); o.feed(new Grass()); a = o; // OK a = (Animal)t; // Warning a = (Animal)t; // OK a = (Animal)t; // compiler time error //o = (Omniwore)a; // NOT OK //a.feed(new Food()); // compile time error //a.feed(new Meat()); // compile time error //a.feed(new Grass());// compile time error } } class Animal{ void feed(SomeFood f){ System.out.println(this.getClass().getName() + " was fed " + f); }; } class Omniwore extends Animal{}; class Tiger extends Animal{}; class Cow extends Animal{}; class Food{public String toString(){return "Food";} }; class Grass extends Food{public String toString(){return "Grass";}}; class Meat extends Food{public String toString(){return "Meat";} };