def main() :
a = Shape()
b = Shape("red")
print(a,b)
c = Circle("blue",False,10)
print(c)
print(c.area())
class Shape:
def __init__(self, color="yellow", filled=True):
self.__color = color
self.__filled = filled
def __str__(self):
return f'({self.__color},{self.__filled})'
class Circle(Shape):
def __init__(self, color="yellow", filled=True, radius=0):
super().__init__(color="yellow", filled=True)
self.__radius = radius
self.__color = color
self.__filled = filled
def area(self):
fullArea = 3.14*((self.__radius)**2)
return fullArea
def __str__(self):
return f'({self.__color},{self.__filled})'+f'(radius = {self.__radius})'
main()
I want to get the answer like this:
(yellow,True) (red,True)
(blue,False)(radius = 10)
314.0
and yes I got it but I want to get the answer even if I remove these two sentences because it was inherited:
self.__color = color
self.__filled = filled
When I try to remove that two sentences, this is what I got:
'Circle' object has no attribute '_Circle__color'
Why this happened and what should I fix for proper inheritance?