zoukankan      html  css  js  c++  java
  • 032_class_inheritance

    #!/usr/bin/env python
    # Author:liujun


    class People(object):
    def __init__(self,name,age):
    self.name = name
    self.age = age

    def eat(self):
    print("%s is eating ...."% self.name)

    def talk(self):
    print("%s is sleeping ..."% self.name)

    def sleep(self):
    print("%s is sleeping...."%self.name)

    class Man(People):

    def __init__(self,name,age,money): # Overwrite the constructor

    #Version 1
    #People.__init__(self,name,age)

    #Version 2
    super(Man,self).__init__(name,age)

    self.money = money
    print("You have %d money when you are borned..."% self.money)

    def piao(self): # This is a new method in Man
    print("%s is piao .... 20s .... done"% self.name)

    def sleep(self): # overwrite the method in sleep
    People.sleep(self)
    print("man is sleeping......")


    class Woman(People):

    def getBirth(self):
    print("%s is born a baby......"% self.name)

    m1 = Man("Liujun",28,100)
    m1.eat()
    m1.piao()
    m1.sleep()

    w1 = Woman("ChenRongHua",26)
    w1.getBirth()
  • 相关阅读:
    Ural 1966 Cycling Roads
    SQL Server 2008 安装(lpt亲测)
    cf Round#273 Div.2
    poj 2318 TOYS
    计算几何好模板
    ❤Friends
    限制pyqt5应用程序 只允许打开一次
    pyqt5 菜单栏+信息提示框
    Android Linux deploy
    system分区解锁
  • 原文地址:https://www.cnblogs.com/liujun5319/p/9637898.html
Copyright © 2011-2022 走看看