我们可以在python中实现这样的构造函数链接吗?
我尝试了一个例子:
import math
class Shape:
def __init__(self, color, filled):
print("hellodata!")
self.__color = color
self.__filled = filled
def get_color(self):
return self.__color
def set_color(self, color):
self.__color = color
def get_filled(self):
return self.__filled
def set_filled(self, filled):
self.__filled = filled
class Rectangle(Shape):
def __init__(self, length, breadth,jdjd,hdhd):
super().__init__(jdjd,hdhd)
self.__length = length
self.__breadth = breadth
def get_length(self):
return self.__length
def set_length(self, length):
self.__length = length
def get_breadth(self):
return self.__breadth
def set_breadth(self, breadth):
self.__breadth = breadth
r1 = Rectangle(10.5, 2.5,'dd','usu')
print("Area of rectangle r1:", r1.get_area())
print("Perimeter of rectangle r1:", r1.get_perimeter())
print("Color of rectangle r1:", r1.get_color())
print("Is rectangle r1 filled ? ", r1.get_filled())