编写矩形类包含私有成员长和宽成员,通过构造函数可以对其初始化,可以计算面积等
编写矩形类的派生类立方体类包含长,宽,高,可以通过构造函数初始化,可以计算体积
class rect:
_Length = 0
_Width = 0
def __init__(self,l,w):
self._Length=l
self._Width= w
def comput_S(self):
return self._Length*self._Width
class rectangle(rect):
Height = 0
def __init__(self,l,w,h):
rect.__init__(self,l,w)
self.Height=h
def comput_V(self):
return rect.comput_S(self)*self.Height
r=rectangle(3,4,5)
print(r.comput_S())
print(r.comput_V())