假设有两个类具有以下接口:
class RegularPolygon:
def __init__(self, sides, length):
self.sides = sides
self.length = length
def area(self):
'''algorithm for calculating area of any regular polygon using math.tan'''
class Square(RegularPolygon):
def __init__(self, length):
super().__init__(4, length)
def area(self):
return self.length ** 2
我希望RegularPolygon(4, 5).area()
通过使用Square
的area
函数而不是RegularPolygon
函数精确返回25。有没有办法让RegularPolygon(4, 5)
实际返回一个Square
对象
目前没有回答
相关问题 更多 >
编程相关推荐