Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago