Welcome to Westonci.ca, your go-to destination for finding answers to all your questions. Join our expert community today! Join our Q&A platform and connect with professionals ready to provide precise answers to your questions in various areas. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.
Sagot :
Answer:
Explanation:
The following code is written in Python. It creates the parent class Shape and the three subclasses Rectangle, Square, and Circle that extend Shape. Shape has the constructor which is empty and the area method which returns 0.0, while the three subclasses take in the necessary measurements for its constructor. Each subclass also has getter and setter methods for each variable and an overriden area() method which returns the shapes area.
class Shape:
def __init__(self):
pass
def area(self):
return 0.0
class Square(Shape):
_length = 0
_width = 0
def __init__(self, length, width):
self._width = width
self._length = length
def area(self):
area = self._length * self._width
return area
def get_length(self):
return self._length
def get_width(self):
return self._width
def set_length(self, length):
self._length = length
def set_width(self, width):
self._width = width
class Rectangle(Shape):
_length = 0
_width = 0
def __init__(self, length, width):
self._width = width
self._length = length
def area(self):
area = self._length * self._width
return area
def get_length(self):
return self._length
def get_width(self):
return self._width
def set_length(self, length):
self._length = length
def set_width(self, width):
self._width = width
class Circle(Shape):
_radius = 0
def __init__(self, radius):
self._radius = radius
def area(self):
area = 2 * 3.14 * self._radius
return area
def get_radius(self):
return self._radius
def set_radius(self, radius):
self._radius = radius
We appreciate your time. Please come back anytime for the latest information and answers to your questions. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. Thank you for trusting Westonci.ca. Don't forget to revisit us for more accurate and insightful answers.