class quadriLateral:
def __init__(self, a, b, c, d):
self.side1=a
self.side2=b
self.side3=c
self.side4=d
def perimeter(self):
p=self.side1 + self.side2 + self.side3 + self.side4
print("perimeter=",p)
class rectangle(quadriLateral):
def __init__(self, a, b):
super().__init__(a, b, a, b)
class square(rectangle):
def __init__(self, a):
super().__init__(a, a)
def area(self):
a=pow(self.side1, 2)
print('Area of Square: ', a)
class TwoDObject:
def __init__(self,x:float=0,y:float=0):
self.x = x
self.y = y
def move(self,xchange:float=0,ychange:float=0):
self.x = self.x + xchange
self.y = self.y + ychange
def area(self):
return 0
class Circle(TwoDObject):
def __init__(self,radius:float=1 , x:float=0, y:float=0):
self.radius = radius
super().__init__(x,y)
def area(self):
return (self.radius*self.radius * 3.14)
def size_change(self,percent:float):
self.radius = self.radius * (percent/100)
What I have tried:
as I know the subclass can only add functionality and properties to the parent class, but can't remove them.
in the second example (TwoDObject class and sub.Cl. Circle) the Circle adds properties to the superclass (TWoD.) (it adds the property radius) and for me it is normal.
whereas in the first example and what I find cranky ( quadrilateral and rectangle )the rectangle removes properties from the superclass (c,d are removed and has only a and b)and the square removes 3 attributes.
MY question is how can the class remove attributes from the parent class and how to do it?