Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Class Student has protected instance variables name, age, and gpa. Constructor has three input parameters and it initializes instance variables. Class Student has method void

Class Student has protected instance variables name, age, and gpa. Constructor has three input parameters and it initializes instance variables. Class Student has method void message() that prints name, age, and gpa of a student. Method message has void as return type, and has no input parameters.

Assume the following inheritance hierarchy of classes.

Class Undergraduate extends class Student.

Class Graduate extends Student.

Class CS extends Undergraduate.

Class Math extends Undergraduate.

Class Undergraduate has additional protected variable seniorProject and class Graduate has additional variable graduateThesis. The constructors of classes Undergraduate and Graduate will reuse the code of their parents constructor as part of the code. Both classes override method message and print seniorProject and graduateThesis, respectively, in addition to printing name,age, and gpa. Both overridden methods message reuse code from method message inherited from Student class to print name,age, and gpa.

Classes CS, and Math have constructors that reuse code for their parents constructor. Neither one of those two classes overrides method message.

Class Testing has main method. In the main method print EXAMPLE 1 and after that instantiate variable oneStudent of Student type. Make that variable refer to an object from Student class and after that make it call method message. Next make it to refer to an object from Undergraduate class, and make variable oneStudent call method message again. Write print statement to explain whether EXAPMLE 1 illustrates polymorphism or not, and explain why or why not.

Next print EXAMPLE 2. After that instantiate variable secondStudent of Undergraduate type. Make secondStudent variable refer to an object from CS class and after that make it call method message. Next make secondStudent to refer to an object from Math class, and make it call method message again. Write print statement to explain whether EXAPLE 2 illustrates polymorphism or not, and explain why or why not.

You do not need to show testing of other methods in class Testing but it is useful to do it.

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

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

More Books

Students also viewed these Databases questions

Question

kaito and wael are solving problems. there are n problems

Answered: 1 week ago

Question

Describe the job youd like to be doing five years from now.

Answered: 1 week ago

Question

So what disadvantages have you witnessed? (specific)

Answered: 1 week ago