2019-06-14
阅读量:
455
什么是继承
面向对象编程的一个主要优点是重用。继承是实现同样的机制之一。在继承中,类(通常称为超类)由另一个类(通常称为子类)继承。子类为超类添加了一些属性。
下面是一个示例Python程序,用于说明如何在Python中实现继承。
# A Python program to demonstrate inheritance
# Base or Super class. Note object in bracket.
# (Generally, object is made ancestor of all classes)
# In Python 3.x "class Person" is
# equivalent to "class Person(object)"
class Person(object):
# Constructor
def __init__(self, name):
self.name = name
# To get name
def getName(self):
return self.name
# To check if this person is employee
def isEmployee(self):
return False






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
3条评论