5. (15 pts) Please answer the following questions about Object-Oriented Programming in python.
(A) A "Rectangle" class is defined on the right.
Please:
(1) generate an instance "r" of class
Rectangle, with x=y=0, and width = 4,
height = 2
(2) print the width
(3) change the width to 6
Your code:
class Rectangle:
def __init__(self, x, y, w, h):
self.x = x
self.y = y
self.w = w
self.h = h
@property
def width(self):
return self.w
@width.setter
def width(self, w):
if w > 0: self.w = w
(B) Given the code for class A, please answer:
(1) what is the meaning of @classmethod?
(2) what is the output of the following code:
>>> a = A()
>>> A.set_class_b()
>>> a.b (Your answer: )
>>> A.b (Your answer: )
>>> a_new = A()
>>> a_new.b (Your answer: )
(C) Please use "Rectangle" as superclass in the
class A:
b = 6
def set_b(self):
self.b = 3
@classmethod
def set_class_b(cls):
cls.b = 7
class Square(Rectangle):
def __init__(self, x, y, s):