# 大师类 class Master(object): def __init__(self): pass # 学校类 class School(object): def __init__(self): pass # 徒弟类 继承学校类和大师类 class Prentice(School, Master): def __init__(self): # 实列属性 子类可以使用 self.kongfu = '[独创煎饼果子配方]' # 定义私有属性 子类不能使用 self.__price = '2000万' # 普通方法 子类可以使用 def make_cake(self): print(f'运用{self.kongfu}制作煎饼果子') # 私有方法 子类不能使用 def __get_money(self): print('这是技术不能传给你') # 徒孙类 class Tusun(Prentice): pass if __name__ == '__main__': tusun = Tusun() print(tusun.kongfu) # 使用普通属性 # print(tusun.__price) # 使用私有属性 报错 tusun.make_cake() # 使用普通方法 # tusun.__get_money() # 使用私有方法
python 多态
最新推荐文章于 2024-07-12 16:16:27 发布