zoukankan      html  css  js  c++  java
  • python学习,day6 继承

    # coding=utf-8
    # Author: RyAn Bi
    class People:
        def __init__(self,name,age):
            self.name = name
            self.age = age
        def  talk(self):
            print('%s is talking'% self.name)
        def sleep(self):
            print('%s is loving sleep'% self.name)
    
    class Man(People):       #继承
        def __init__(self,name,age,money):  #重构父类,不在调用上面的属性,所以属性要和上面父类一致(可以多),否则调用失败
            People.__init__(self,name,age)  #把父类里面有的,再执行一遍
            #super(Man,self)__init__(name,age)   #另外一种父类重构,好处是可以多继承,例如people有很多个
            self.money = money     #父类里没有的,单独定义一遍
        def sleep(self):
            People.sleep(self)     #重构父类
            print('%s is sleeping'% self.name)
        def piao(self):
            print("%s say hi baby,come on "%self.name)
    
    class Woman(People):       #继承
        def get_birth(self):
            print('%s is birthing baby '%self.name)
    
    
    m1 = Man('bb',22,10)
    m1.sleep()    #继承和重构sleep
    m1.talk()     #继承talk
    m1.piao()     #子类的piao
    w1 = Woman('uu',22)
    w1.piao()     #兄弟类不能继承
  • 相关阅读:
    48音标
    business expressions(二)
    Pick up lines搭讪
    Greetings
    business expressions(一)
    analyzing problems
    business meeting
    idea缓存目录mac cache
    Sublime 3156 LICENSE key
    React从0到1
  • 原文地址:https://www.cnblogs.com/bbgoal/p/12185641.html
Copyright © 2011-2022 走看看