Inheritance in 2018-07-05-python full stack development Day25-python

Source: Internet
Author: User

#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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.