The inheritance of the three major features of Python object-oriented

Source: Internet
Author: User


#继承
#object base class, which is the parent class for all classes defined by Python
#经典类: Classes that do not inherit object are called Classic classes
#新式类: Classes that inherit object are called modern classes
#python 3.x unified for new class
#经典类是类对象, a new class is a type Object

#经典类的继承是按照继承的顺序进行继承的

#新式类是按照修改的优先级来继承, the higher the change priority is.

Class Parent: #定义一个父类
def __init__ (self):
Self.age = 0
def sing (self):
Print ("Sing a Song 2")

Class Child (Parent): #定义一个子类
def sleep (self):
Print ("Zzzzzzz ....")
def sing (self): #重写, retains the parent property while having its own property
Parent.sing (self)
Print (self)
Print ("Sing a Song 1")

Father = Parent ()
son = Child ()
Print (Son.age)
Son.sing () #---> child.sing (son)

"""

0
Sing a Song 2
<__main__. Child object at 0x00000000007ecef0>
Sing a Song 1

"""

The inheritance of the three major features of Python object-oriented

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.