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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started