python multiple inheritance order of constructor calls

  • The example code
    class the Person (Object):
         DEF  the __init__ (Self, name, Age): 
            the self.name = name 
            self.age = Age
             Print ( " parent class constructor " ) 
    
    
        DEF Talk (Self):
             Print ( " Person ... IS Talking . " ) 
    
    
    class Chinese (the Person):
         DEF  __init__ (Self, name, Age, Language):   # first inheritance, in the reconstruction 
            . the Person __init__ (Self, name, Age)   # constructor inherits the parent class can also be written as: super (Chinese, self) .__ init __ (name, age)
            Language = self.language   # own class property definitions 
            Print ( " sub-class constructor " ) 
    
        DEF Walk (Self):
             Print ( ' IS ... walking ' ) 
    
    
    class American (Chinese):
         DEF  the __init__ (Self, name, Age , Language, height): 
            Chinese. the __init__ (Self, name, Age, Language) 
            self.height = height
             Print ( " Sun class constructor " ) 
    
    
    C = American ( ' bigberg ' , 22 is, 'Chinese',180)

     

  • operation result
    D: \ Software Installation \ Python3.7.4 \ python.exe E: / Python / pythonfile20190907 / OOP6.py 
    parent class constructor 
    subclass constructor 
    Sun class constructor 
    
    Process finished with exit code 0

     

Guess you like

Origin www.cnblogs.com/ybl20000418/p/11491903.html