Python Practice › OOP Programs › Program 39
Manager with bonus
Create Manager (inherits Employee) with department and bonus, and a method for total compensation.
Output
Ravi QA 1350000
Approach
- Total = salary + bonus.
Solution
class Employee: def __init__(self, name, salary): self.name, self.salary = name, salary class Manager(Employee): def __init__(self, name, salary, department, bonus): super().__init__(name, salary) self.department, self.bonus = department, bonus def total(self): return self.salary + self.bonus m = Manager("Ravi", 1200000, "QA", 150000)print(m.name, m.department, m.total())Output
Ravi QA 1350000
Learn the concept
New to this topic? Read the lesson, then come back.