Consider the following classes : Note: please solve with java, thanks. {private E animal;public void setAnimal(E x) {animal = x;}public E getAnimal() {return animal;}}public class...

Consider the following classes : Note: please solve with java, thanks.
public class AnimalHouse<E> {<br>private E animal;<br>public void setAnimal(E x) {<br>animal = x;<br>}<br>public E getAnimal() {<br>return animal;<br>}<br>}<br>public class Animal{<br>}<br>public class Cat extends Animal {<br>public class Dog extends Animal {<br>}<br>For the following above code snippets, identify whether the code:<br>1. Fails to compile,<br>2. Compiles with a warning,<br>3. Generates an error at runtime, or<br>4. None of the above (compiles and runs without problem.)<br>Question la. AnimalHouse<Animal> house = new AnimalHouse<Cat>();<br>Question 1b. AnimalHouse<Cat> house = new AnimalHouse<Animal>();<br>Question 1c. AnimalHouse<?> house = new AnimalHouse<Cat>();<br>house.setAnimal(new Cat());<br>Question 1d. AnimalHouse house = new AnimalHouse();<br>house.setAnimal(new Dog());<br>

Extracted text: public class AnimalHouse { 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 above code snippets, identify whether the code: 1. Fails to compile, 2. Compiles with a warning, 3. Generates an error at runtime, or 4. None of the above (compiles and runs without problem.) Question la. AnimalHouse house = new AnimalHouse(); Question 1b. AnimalHouse house = new AnimalHouse(); Question 1c. AnimalHouse house = new AnimalHouse(); house.setAnimal(new Cat()); Question 1d. AnimalHouse house = new AnimalHouse(); house.setAnimal(new Dog());

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here