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)
  • 相关阅读:
    ●sql语句-添加表和字段的说明
    ●sql-行列转换
    ●获取汉字全拼
    ●获取汉字首拼
    ●导出excel(NPOI)
    ●导出excel(office组件)
    JQuery
    CSS网页美化设计属性
    表单 框架集及CCS 20140916
    常见标签的属性及使用 20140915
  • 原文地址:https://www.cnblogs.com/liujun5319/p/9637919.html
Copyright © 2011-2022 走看看