Question: public abstract class Animal { private String name; public abstract void talk(); public String getName() { return name; } public void setName (String animalName) {
public abstract class Animal { private String name; public abstract void talk(); public String getName() { return name; } public void setName (String animalName) { name = animalName; } } public class Cat extends Animal { public void talk() { System.out.println("Meow"); } } public interface Worker { public void work(); } Now create a WorkingCat class that extends Cat and implements Worker. A WorkingCat contains a data field that a regular Cat does not: an int that holds hours of training received called 'hoursOfTraining'. The WorkingCat class also contains get and set methods for 'hoursOfTraining'. Because the WorkingCat class implements the Worker interface, it also must override the work() method. In this example the work() method calls the Cat's talk() method, and then produces 2 more lines of output: a statement about working such as "I am a cat who works" and the number of training hours. Finally, create a WorkingCatDemo.java application that instantiates 2 WorkingCat objects. Each object will call setName() and setHoursOfTraining() to do just that. Each object will then use getName() to output its name and then talk() and work() Here is sample output: Simon, the Cheshire Cat says Meow Meow I am a cat who works I have 40 hours of professional training Tony, the Tiger says Meow Meow I am a cat who works I have 300 hours of professional training
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
