热线电话:13121318867

登录
2019-04-29 阅读量: 455
如何通过父类提取子类中的父成员?

如何使用父类名称访问子类中的父成员?

# Python example to show that base

# class members can be accessed in

# derived class using base class name

class Base(object):

# Constructor

def __init__(self, x):

self.x = x

class Derived(Base):

# Constructor

def __init__(self, x, y):

Base.x = x

self.y = y

def printXY(self):

# print(self.x, self.y) will also work

print(Base.x, self.y)

# Driver Code

d = Derived(10, 20)

d.printXY()

输出:

10,20
75.0000
0
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子