#class Eat:#def __init__ (self):#print (' Eat ')#def Eat (self):#print (' Eat ')##class Run:#def __init__ (self):#print (' Run ')#class Cat (eat,run):#def __init__ (self):#print (' This is a cat ')#def Eat (self):#print (' This is sons eat ')#class Dog (eat,run):#def __init__ (self):#print (' This is a dog ')#P1=cat ()#p1.eat ()
#class Father:#def __init__ (self,name,age,gender):#Self.name=name#Self.age=age#Self.gender=gender#def test (self):#print (' This is Father S ')#class Son (Father):#def __init__ (self,name,age,gender,school): #如果儿子和父亲在name, Age,gender and so on, the stupid way is to write again## self.name = name## self.age = Age## Self.gender = gender# and then writes the subclass's unique properties## father.__init__ (self,name,age,gender) #此方法如果父类的名字改变, there is no#super (). __init__ (Name,age,gender) #方便之处是不用在意父类的名字改变, and do not add self#Self.school=school#def test (self):## father.test (self) #最古老的方法#super (). Test ()##P1=son (' yehiabin ', ' + ', ' male ', ' sdau ')#p1.test ()##print (p1.name)
ImportABCclassJilei (metaclass=ABC. Abcmeta): @abc. AbstractmethoddefWrite (self):Print('This is write') @abc. AbstractmethoddefRead (self):Print('This is read')classSon (jilei):defWrite (self):Print('This is son') P1=son () p1.write ()
Traceback (most recent): " c:/users/brown/pycharmprojects/python_s3/dya25/inheritance. PY " in <module> p1=son () typeerror:can't instantiate abstract Class son with abstract methods read# must write another read method to match the base class
Inheritance in 2018-07-05-python full stack development Day25-python