// AnimalGenericTest<Integer> x = new AnimalGenericTest<Integer>(); // NO! Will not compile, // because it takes only Animal of subclass of animal type object not Integer dog.getT().eat(); cat.getT().eat();

System.out.println("End of class........"); }}

--------------------------------------------------
The output will be as..........

C:\SCJP6\generics>javac AnimalGenericTest.java

C:\SCJP6\generics>java AnimalGenericTestDog is eating....Cat is eat....End of class........

----------------------------------------------------------
Qu3. How will you use generic method in this code??

public <T> void makeArrayList(T t) { // take an object of an // unknown type and use a "T" to represent the type List<T> list = new ArrayList<T>(); // now we can create the list using "T" list.add(t); System.out.println("List is:"+list.toString()); }

// AnimalGenericTest<Integer> x = new AnimalGenericTest<Integer>(); // NO! Will not compile, // because it takes only Animal of subclass of animal type object not Integer dog.getT().eat(); cat.getT().eat();dog.makeArrayList(dog.getT());