包含关系(has it)
继承关系(is it)
class Person:
def __init__(self, no, name, salary):
self.no = no
self.name = name
self.salary = salary
def __str__(self):
msg = self.no + "---" + self.name + '---' + self.salary
return msg
def getSalary(self):
return self.salary
class Worker(Person):
def __init__(self, no, name, salary, hours, hou_money):
super().__init__(no, name, salary)
self.hours = hours
self.per_hour = hou_money
def getSalary(self):
money = self.per_hour * self.hours
self.salary += money
return self.salary
class Salesman(Person):
def __init__(self, no, name, salary, sale_money, percent):
super().__init__(no, name, salary)
self.sale_money = sale_money
self.percent = percent
def getSalary(self):
money = self.sale_money * self.percent
self.salary += money
return self.salary
worker = Worker("001", "king", 2000, 160, 100)
salary = worker.getSalary()
print(salary)