기본 클래스의 메서드를 상속 된 클래스의 재정의하는 메서드 대신 동일한 클래스의 다른 메서드를 호출 할 싶습니다. 다음 코드는상속 및 기본 클래스 메서드 호출 파이썬
클래스 B를 출력하고 싶은 : 6 개
클래스 A : 9
가이 작업을 수행 할 수 있습니까? http://docs.python.org/tutorial/classes.html#private-variables 및 http://docs.python.org/reference/expressions.html#atom-identifiers에서 :
# Base class definition
class ClassA(object):
def __init__(self):
print("Initializing A")
# hoping that this function is called by this class's printFnX
def fnX(self, x):
return x**2
def printFnX(self, x):
print("ClassA:",self.fnX(x))
# Inherits from ClassA above
class ClassB(ClassA):
def __init__(self):
print("initizlizing B")
def fnX(self, x):
return 2*x
def printFnX(self, x):
print("ClassB:", self.fnX(x))
ClassA.printFnX(self,x)
bx = ClassB()
bx.printFnX(3)
어떤 대답을 허용으로 표시했는지 다시 생각해 보시나요? 현재 선택은 대부분의 사람들과 대부분의 유스 케이스에 대한 나쁜 조언이다. –