zoukankan      html  css  js  c++  java
  • python_super注意事项

    class room:
    def __init__(self,area=120,usedfor='sleep'):
    self.area = area
    self.usedfor = usedfor
    def display(self):
    print("this is my house")

    class babyroom(room):
    def __init__(self,area=40,usedfor="son",wallcolor='green'):
    super().__init__(area,usedfor)
    self.wallcolr = wallcolor
    def display(self):
    super().display()
    print("babyroom area:%s wallcollor:%s"%(self.area,self.wallcolr))

    class rent:
    def __init__(self,money=1000):
    self.rentmoney = money
    def display(self):
    print("for rent at the price of %s"%self.rentmoney)

    class agent(babyroom,rent):
    #class agent(rent,babyroom):
    def display(self):
       super().display()
    print("rent house agent")
    agent().dispaly()


    output:

      class agent(babyroom,rent)类输出为:
        this is my house
        babyroom area:green wallcollor
        rent house agent
      
    class agent(rent,babyroom)类输出:

        for rent at the price of 1000
        rent house agent
     


  • 相关阅读:
    Java面向对象(三)
    Java面向对象(二)
    Java面向对象(一)
    java基础(六)
    java基础(五)
    java基础(四)
    java基础(三)
    java基础2
    java基础
    计算机内存
  • 原文地址:https://www.cnblogs.com/jiejunwang/p/8477458.html
Copyright © 2011-2022 走看看