Question: OOP IN JAVA!!! HELPMEPLEASE Class Wolf is a subclass of class Animal. Consider the following code. Wolf wolf1 = new Wolf(Scott); // sets instance variable
OOP IN JAVA!!! HELPMEPLEASE
Class Wolf is a subclass of class Animal. Consider the following code.
Wolf wolf1 = new Wolf("Scott"); // sets instance variable "name" at Animal level
Animal animal1 = new Wolf("Isaac"); // sets instance variable "name" at Animal level
Animal animal2 = new Animal("Joe"); // sets instance variable "name" at Animal level
ArrayList
zoo.add(wolf1);
zoo.add(animal1);
zoo.add(animal2);
// Note: there is a howl() method in the Wolf class.
for (Animal animal : zoo) {
((Wolf) animal) .howl();
}
A: Scott and Isaac will howl; then we will get a runtime error.
B: The code will not compile, so we will never know who will howl.
C: Nobody will howl; we will get a runtime error.
D: Only Scott will howl; then we will get a runtime error.
E: Scott, Isaac, and Joe will all howl; and there will be NO runtime error.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
