zoukankan      html  css  js  c++  java
  • Python基础之继承

    #继承实现


    #父亲会书法,大儿子和小儿子会书法
    #父亲一般能吃,大儿子吃超过,小儿子吃得少
    class father:
        def write(self):
            print   'i can write'
    class oldbrother(father):#class A(B)子类A继承父类B
        def eat(self):
            print "i eat too much"
    class elderbrother(father):
        def noeat(self):
            print "i can't eat"
    daerzi=oldbrother()
    daerzi.write()
    daerzi.eat()
        
    #多继承
    class muniu:
        def eat(self):
            print 'i can eat'
    class gongniu:
        def run(self):
            print 'i can run'
    class daniu(muniu,gongniu):#class A(B,C,D)
        pass
    class xiaoniu(muniu):
        pass
    daniu=daniu()
    daniu.eat()
    daniu.run()
    xiaoniu=xiaoniu()
    xiaoniu.eat()
    #xiaoniu.run()
              
    #多继承冲突,从左到右继承(父类方法名相同时候)
    class muniu:
        def eat(self):
            print 'i can eat'
    class gongniu:
        def run(self):
            print 'i can run'
        def eat(self):
            print 'i can eat,too'
        
    class daniu(muniu,gongniu):#class A(B,C,D)
        pass
    daniu=daniu()
    daniu.eat()

  • 相关阅读:
    前端学习:html基础学习四
    前端学习:html基础学习三
    cogs 2691. Sumdiv
    cogs 421. HH的项链
    Bzoj 2038: [2009国家集训队]小Z的袜子(hose)
    【NOIP模拟赛】密码锁
    cogs1612. 大话西游
    cogs1583. [POJ3237]树的维护
    Bzoj 3343: 教主的魔法
    SPOJ375 Query on a tree
  • 原文地址:https://www.cnblogs.com/jietingting/p/7076963.html
Copyright © 2011-2022 走看看