Question: QUESTION 2 Question 2 covered about class, objects, inheritance and polymorphism concept. Answer the following questions. a) Reproduce the program below with appropriate class name,

QUESTION 2 Question 2 covered about class, objects, inheritance and polymorphism concept. Answer the following questions. a) Reproduce the program below with appropriate class name, data members and method based on Figure 2(a). public class Animal public String group: public int age; public void displayinfo( X System.out.println("Group Name:"name); System.out.println("Animal Age (years): "+ age): } Figure 2(a) [2 marks) b) Constructs a subclass named Cat for the Animal class as Figure 2(a) and declare an instance variable named type (String) in the Cat class. (Hint: type= Omnivore) [8 marks) c) Constructs a constructor in Cat class and give appropriate initial values for the instance variables (group and age) in the Animal class by using super keyword and also for the type in Cat class by using this keyword. [8 marks) d) Constructs an overriding method displayinfo() in Cat class, invoke the superclass displayinfo) method by using super keyword. displayInfo() method in Cat class should display the information of Cat's type, age from the superclass and type from the subclass. [4 marks) e) Constructs another class named Main for the main() method and create object for the Cat class. Then execute the displayInfo() method for Cat class. Example of the output as in Figure 2(e). Cat's Info: Group Name : Mammal Animal Age (years): 2 Type : Omnivore Figure 2(e) [4 marks]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
