Create class employees with function salary inherit by using Developer class and Tester class with suitable functions that can calculate the salary of employees. Use variables Ename, esalary, ecompany etc.
Code:
class Employee:
def __init__(self, name, salary, company):
self.name = name
self.salary = salary
self.company = company
def calculate_salary(self):
raise NotImplementedError("Subclass must implement abstract method")
class Developer(Employee):
def __init__(self, name, salary, company, bonus):
super().__init__(name, salary, company)
self.bonus = bonus
def calculate_salary(self):
total_salary = self.salary + self.bonus
return total_salary
class Tester(Employee):
def __init__(self, name, salary, company, overtime_pay):
super().__init__(name, salary, company)
self.overtime_pay = overtime_pay
def calculate_salary(self):
total_salary = self.salary + self.overtime_pay
return total_salary
# Example usage
if __name__ == "__main__":
# Create instances of Developer and Tester
developer = Developer("John", 50000, "ABC Corp", 10000)
tester = Tester("Alice", 45000, "XYZ Inc", 5000)
# Calculate salaries
developer_salary = developer.calculate_salary()
tester_salary = tester.calculate_salary()
# Print salaries
print("Developer Salary:", developer_salary)
print("Tester Salary:", tester_salary)
0 Comments