Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java please Define an interface FarmAnimal that contains two methods: getName() and talk(), each returns a string. Declare an abstract class FarmAnimalBase that implements

In Java please

Define an interface FarmAnimal that contains two methods: getName() and talk(), each returns a string. Declare an abstract class FarmAnimalBase that implements the interface FarmAnimal. In the class FarmAnimalBase, define a private final instance variable name (type: String), a public constructor that initializes the value of the instance variable name, and a public method getName() that returns the value of the instance variable name. Note that we do not implement the method talk() declared in the interface FarmAnimal, thats the very reason we have to declare the class FarmAnimalBase as an abstract class. Make three classes, Cat, Dog, and Cow, that inherit from FarmAnimalBase. Each of the inherited classes has a constructor that initializes the value of the instance variable. Each of the inherited classes also implements a method (prototype: public String talk();), which contains only one line of code. For class Cat, return "Meow! Meow!"; for class Dog, return "Arf! Arf!"; and for class Cow, return "Moo! Moo!"; Supply a test program FarmAnimalTest that tests these classes and methods. Specifically, create three objects, one each from the classes Cat, Dog, and Cow using the names - "Missy", "Lassy", and "Nossy". Then put all these three objects into an ArrayList farmAnimals of FarmAnimal objects. And finally, show the farm animal names and sounds they make. The output should look exactly like the following: Missy: Meow! Meow! Lassy: Arf! Arf! Nossy: Moo! Moo!

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

Solve each equation. 2x = 3x + 12-2

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago