Consider the following classes:
public class AnimalHouse<E> { private E animal; public void setAnimal(E x) { animal = x; } public E getAnimal() { return animal; } } public class Animal{ } public class Cat extends Animal { } public class Dog extends Animal { }
For the following code snippets, identify whether the code:
AnimalHouse<Animal> house = new AnimalHouse<Cat>();
AnimalHouse<Cat> house = new AnimalHouse<Animal>();
AnimalHouse<?> house = new AnimalHouse<Cat>(); house.setAnimal(new Cat());
AnimalHouse house = new AnimalHouse(); house.setAnimal(new Dog());
Design a class that acts as a library for the following kinds of media: book, video, and newspaper. Provide one version of the class that uses generics and one that does not. Feel free to use any additional APIs for storing and retrieving the media.