【发布时间】:2010-10-01 21:43:39
【问题描述】:
是否可以在子类中将公共方法设为私有?我不希望扩展这个类的其他类能够调用某些方法。这是一个例子:
class A:
def __init__(self):
#do something here
def method(self):
#some code here
class B(A):
def __init__(self):
A.__init__(self)
#additional initialization goes here
def method(self):
#this overrides the method ( and possibly make it private here )
从现在开始,我不希望任何从 B 扩展的类能够调用 method。
这可能吗?
编辑:这样做的“逻辑”原因是我不希望用户以错误的顺序调用方法。
【问题讨论】:
标签: python oop inheritance