Created
September 17, 2018 15:40
-
-
Save pknowledge/81ef5bb368b62395e538e43ea367da03 to your computer and use it in GitHub Desktop.
Python Composition Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Salary: | |
def __init__(self, pay, bonus): | |
self.pay=pay | |
self.bonus=bonus | |
def annual_salary(self): | |
return (self.pay*12) + self.bonus | |
class Employee: | |
def __init__(self, name, age, pay, bonus): | |
self.name=name | |
self.age=age | |
self.obj_salary=Salary(pay, bonus) | |
def total_salary(self): | |
return self.obj_salary.annual_salary() | |
emp = Employee('max', 25, 15000, 10000) | |
print(emp.total_salary()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment