Question: The code below is contained in the main method of another program. Animal a = new Animal(); Animal b = new Dog(Brown, Rover); Dog d1

The code below is contained in the main method of another program.

Animal a = new Animal();

Animal b = new Dog("Brown", "Rover");

Dog d1 = new Poodle("White", "Mr. Barksworthy");

Poodle fluffy = new Poodle("Black", "Ferdinand");

Poodle p = d1;

1.) Given the above declarations, what will the following statement do?

d1.noise();

2.) Given the above declarations, discuss the statement below. Will it compile? If so, what will its output be? Explain. If it will not compile, explain why not.

b.noise();

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public interface NoiseMaker {

public void noise();

}

Public abstract class Animal {

protected String color;

public Animal() { color=""; }

public abstract void print();

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class dog Extends Animal implements Noisemaker {

{

protected String name;

public Dog(String c, String n) { color = c; name = n; }

public void print() { System.out.println(name); }

public void noise() { System.out.println("woof"); }

}// Dog class

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!