包含(has it)、继承(is it)

包含关系(has it)

包含(has it)、继承(is it)_第1张图片包含(has it)、继承(is it)_第2张图片

继承关系(is it)

包含(has it)、继承(is it)_第3张图片

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)

你可能感兴趣的:(python,开发语言)