Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2 Consider the following program: (5pts each, total 20 pts 1 Fig. 10.9: Payrolls

ID: 3816995 • Letter: 2

Question

2 Consider the following program: (5pts each, total 20 pts 1 Fig. 10.9: Payrollsystenrest java 2 Employee hierarchy test program 4 public class payrollsystemTest public static void nat string args create subclass objects salariedEmployee new salariedEnployeec John?, Smith 111-11-1111 800.00) 11 HourlyEmployee hourlyEnployee "Price", 222-22-2222", 16.75, 40 new Enployee("aren 13 Commission Employee comissionEmpl new comission Enployee( 14 'sue", "Jones", 333-33-3333 10000, 06 moyee basePlusconmissionEmployee Base new BasePluscommission "Bob", "Lewis "444 4454 5000. .04, 300 19 20 system out, printinc Employees processed individuallyyn" salariedemployee alariedEmployee earnings CD hourly Employee "earned hourlyEmployee ings system, out 2 AnAn earned". nings commission Employee base PluscommissionEmployee base Plus commissi Employee. earnings co create four element Employee array Employee employees new Employee t 4 1 array with Employees employees o salariedEmployee employees 1 hourly Employee employees t 21 commission Employee: employees 3 base on Employee em out printinc employees processeo polymorph1can yun" for generi cally process employees Employee each element in array current Employee employees system out printinc current Employee invokes tostring

Explanation / Answer

let start the answer of the following question as follows :

A) No the objects from 36 to 39 are not of the same class. they are of different subclasses . as subclass can always be assigned to parrent calss we can store objects of differnt class into an array it wont create an issue at all.

B) yes current employee is an iterator object which is assigned the value by for-each loop . they for each loops stores the value of employee one by one into the currentemployee object and hence printed .

C)on line 49 the if statement checks the condition that whether the currentemployee is an insatnce of BasePlusCommissionEmployee.

the instance of checks the type of object of both the parent and child for comparison

D)the line 53 and 54 are used to downcast the current employee object to the BasePlusCommissionEmployee . as this procedure is know as type casting of object . it is done to make the object compatible for the other child object .

thanks :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote