【发布时间】:2018-10-03 09:24:21
【问题描述】:
class Base():
def __init__(self):
print("test")
def first_func(self):
print("first function call")
class Deriv(Base):
def __init__(self):
Base.__init__(self)
def first_func(self):
print("Test Derived")
C = Deriv()
C.first_func() # It gives output "Test Derived"
如何仅使用对象 C 和 python 2.7 从基类 (Class Base) 调用 first_func() 方法(输出应为“第一个函数调用”)?
【问题讨论】:
-
您当前正在执行一种称为“覆盖”方法的操作。查看此article 了解更多信息!
标签: python inheritance polymorphism