Objective
Inheritance lets a subclass reuse a base class and specialize it, and polymorphism makes the same method behave differently depending on the object. With super() the method of the base class is reused.
Instructions
- Define
Employeewithname,baseand a methodsalary()that returns the base salary. - Define
Manager(inherits fromEmployee, has abonusand its salary is the base plus the bonus) andSeller(hassalesand its salary is the base plussales // 10). Usesuper()in the constructor and insalary. - Read
nand thennlineskind name base extra, withkindequal toemployee,managerorseller(for ordinary employees,extrais not used but always appears). - Show
name: salaryfor each one, in input order, and at the endTotal payroll: t.
3
employee ana 1000 0
manager luis 2000 500
seller eva 800 1234
ana: 1000
luis: 2500
eva: 923
Total payroll: 4423
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise