Question: - Animal class defines the sound method. This method is abstract and will be implemented by an animal class - > public abstract String sound();
- Animal class defines the sound method. This method is abstract and will be implemented by an animal class - > public abstract String sound(); /** Return animal sound */
- Chicken class implements Edible to specify that chickens are edible. When a class implements an interface, it implements all the methods defined in the interface with the exact signature and return type.
- Chicken class implements the howToEat method. Chicken also extends Animal to implement the sound method.
- Fruit class implements Edible. It does not implement howToEat method. Fruit must be denoted as abstract. The concrete subclasses of Fruit must implement the howToEat method. Apple and Orange classes implement the howToEat method.
-The main method creates an array with objects and invokes the howToEat method if the element is edible and the sound method if the element is an animal
- The Edible interface defines common behavior for edible objects. All edible objects have the howToEat method.
-Implement Animal class by Comparable interface and Cloneable interface that implements two methods getWeight() and setWeight().
1. Add the weight property in the Animal class with getter/setter methods.
2. Two animals are compared based on their weights.
Use this main method code to run:
public static void main(String[] args) { Animal[]list = new Animal[5]; list[0] = new Chicken(); list[0].setWeight(4.5); list[1] = new Tiger(); list[1].setWeight(46.6); list[2] = new Chicken(); list[2].setWeight(1.5); list[3] = (Animal)(list[0].clone()); list[3].setWeight(7.5); list[4] = (Animal)(list[1].clone()); java util.Arrays.sort(list); for(int i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
