首页 > 编程语言 > 详细

Python 类的多态

时间:2018-09-02 18:21:21      阅读:208      评论:0      收藏:0      [点我收藏+]
#python的多态


class Dog():
        def eat(self):
                print("i am dog , eat something . ")


class Cat():
        def eat(self):
                print("i am cat , eat somthing .")


#多态的调用形式
def animal_eat(one):
        one.eat()




d = Dog()

c = Cat()

animal_eat(d)

animal_eat(c)

‘‘‘
python本身属于弱类型语言,变量本身没有类型
python的多态并非是里氏替换原则,仅仅是因为这个对象恰好有这个方法就行,甚至不需要存在继承


‘‘‘

 

Python 类的多态

原文:https://www.cnblogs.com/zhanggaofeng/p/9574455.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!