Question: 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

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!