• 类的多态


    多态的要素
    继承
    重写方法
    实例
    class Program(object):
    name = 'Mike'

    def __init__(self, age, sex, weight):
    self.age = age
    self._sex = sex
    self.__weight = weight

    def intro(self):
    print('my name is ', self.name)
    print('my age is ', self.age)


    class BProgram(Program):
    def __init__(self, age, sex, weight, language):
    super(BProgram, self).__init__(age, sex, weight)
    self.language = language

    def intro(self):
    print('my age is %s my language is %s' % (self.age, self.language))


    def introduction(program):
    if isinstance(program, Program):
    program.intro()


    if __name__ == '__main__':
    program = Program(12, 'female', 34)
    bProgram = BProgram(22, 'male', 50, 'python')
    introduction(program)
    introduction(bProgram)
    ————————————————

  • 相关阅读:
    微信小程序
    正则常用表达式
    nodejs基本
    node初学制作登录服务器实例
    前端面试题集锦(三)
    编程:
    js常见编程题
    前端面试题集锦(二)
    细节问题
    前端面试题集锦(一)
  • 原文地址:https://www.cnblogs.com/ly570/p/11408530.html
Copyright © 2020-2023  润新知