zoukankan      html  css  js  c++  java
  • 033_class_Mul-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 Relation(object):
    def makeFriends(self,obj):
    print("%s is making friends with %s"%(self.name,obj.name))


    class Man(People,Relation):

    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,Relation):

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

    m1 = Man("Liujun",28,100)
    w1 = Woman("ChenRongHua",26)

    m1.makeFriends(w1)
  • 相关阅读:
    [NOI2021] 路径交点
    CF1188D Make Equal
    CF1349F1 Slime and Sequences
    CF1067D Computer Game
    Dcat Admin安装
    PHP 中提示undefined index如何解决(多种方法)
    Git 常用命令大全
    项目维护环境部署
    bootstrap-table
    bootstrap-datetimepicker
  • 原文地址:https://www.cnblogs.com/liujun5319/p/9637919.html
Copyright © 2011-2022 走看看