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 = new 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!