Study Notes (14): 21 days clearance Python (Video Lesson only) - to be rewritten method invocation and call the parent class constructor ...

Learning immediately: https://edu.csdn.net/course/play/24797/282193?utm_source=blogtoedu

'' ' 
1. call parent class Key are overwritten 
2. The call parent class constructor method using unbound 
3. super () function call key parent class constructor 
' '' 


class FuleiFun: 
    DEF the __init __ (Self , NUM): 
        self.num NUM = 2 * 
        Print ( 'parent class name S%'% NUM) 

    DEF toolsFun (Self): 
        Print ( 'parent class toolsFun [method]') 


class ZileiFun (FuleiFun): 
    DEF the __init __ ( Self, NUM): 
        # self.num NUM = 
        # Print ( 'S subclass name%'% NUM) 
        # class constructor of the parent application 
        # method, class calls 
        # FuleiFun .__ the init __ (Self, NUM) 
        # method two , super () method 
        Super () .__ the init __ (NUM) 

    DEF toolsFun (Self): 
        Print ( 'subclass [method] toolsFun')

    useTools DEF (Self): 
        Print ( "subclasses tools method ') 
        # Such method can only be called a subclass overrides 
        self.toolsFun () 
        # original method call parent class 
        FuleiFun.toolsFun (Self) 


ZL = ZileiFun ( 1000) 
zl.useTools () 
# override __init__ constructor 1000 = NUM 
Print ( 'constructor results:% d'% zl.num)
Published 25 original articles · won praise 4 · Views 602

Guess you like

Origin blog.csdn.net/happyk213/article/details/105197107
Recommended