โ Back to Polymorphism
Question 575
Polymorphic Payroll
Polymorphic Payroll
Build a payroll hierarchy from scratch. Define anabstractclassEmployeewith an abstract methodint WeeklyPay(). Then define two subclasses: -HourlyEmployee(int rate, int hours)whose pay israte * hours-SalariedEmployee(int annualSalary)whose weekly pay isannualSalary / 52The tester stores them in aList<Employee>and totals the weekly pay. Do NOT write aMainmethod. ForHourlyEmployee(20, 40)(pay 800) andSalariedEmployee(52000)(weekly 1000) the program prints: 1800
Expected Output:
1800
Topics:
Polymorphism
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.