Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions

Question

Relational Contexts in Organizations

Answered: 1 week ago