python learning, day5: Inheritance

# coding=utf-8
# Author: RyAn Bi
class People:
    def __init__(self,name,age):
        self.name = name
        self.age = age
    def  talk(self):
        print('%s is talking'% self.name)
    def sleep(self):
        print('%s is loving sleep'% self.name)

class Man(People):       #继承
    def sleep(self):
        People.sleep(self)     # Reconstruction parent 
        Print ( ' % S IS Sleeping ' % self.name)
     def piao (Self):
         Print ( " % S say hi Baby, Come ON " % self.name) 

class Woman (People):        # inherited 
    def get_birth (Self):
         Print ( ' % S IS Birthing Baby ' % the self.name) 


M1 = Man ( ' BB ' , 22 is ) 
m1.sleep ()     # inheritance and reconstruction SLEEP 
m1.talk ()      # Inherited talk
m1.piao ()      # Piao subclass 
W1 = Woman ( ' Uu ' , 22 is ) 
w1.piao ()      # sibling classes can not inherit

 

Guess you like

Origin www.cnblogs.com/bbgoal/p/11714611.html