I have two classes 'Employee' (composite class) and 'Salary' (component class).
I want to get value of a variable named 'self.abc' (defined in Employee class) in 'Salary' class. How can I get that?
Currently I'm getting an error AttributeError: 'Salary' object has no attribute 'abc'. Please help.
I don't wanna use inheritance approach here.
class Employee:
def __init__(self, pay, bonus):
self.abc = 100
self.pay = pay
self.bonus = bonus
self.obj_salary = Salary(self.pay)
self.annual_salary()
def annual_salary(self):
print("Total: " + str(self.obj_salary.get_total() + self.bonus))
class Salary:
def __init__(self, pay):
self.pay = pay
def get_total(self):
print(self.abc) # want to get 'abc' value here from 'Employee' class
return (self.pay*12)
obj_emp = Employee(600, 500)