Question
Suppose in the hierarchy of animal classes (see Fig 1) you forget to define the Zebra class. Now you have to add it after all
Suppose in the hierarchy of animal classes (see Fig 1) you forget to define the Zebra class. Now you have to add it after all the classes are created. How can you create the Zebra class in the best possible way to avoid redundancy and what do you think is the worst case of the Zebra class creation? (Hint: Zebra is similar to Horse in characteristics )
If the structure of the Animal and the Horse class is given as:
public class Animal {
public void eat() {
System.out.println (grass or meat);
}
}
public class Horse extends Animal {
public void eat() {
System.out.println("Eats grass");
}
public void speak(){
System.out.println("Neigh");}
}
Write the code to add the Zebra class.
Animal Horse Producer Pig Cow Sheep GoatStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started