1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Tju [1.3M]
4 years ago
9

Create a base class named rectangle that contains lenght and width data members.

Computers and Technology
1 answer:
kumpel [21]4 years ago
4 0

Answer:

class Rectangle:  

   

   def __init__(self, length, width):

       self.length = length

       self.width = width

       

   

   def area(self):

       area = self.length*self.width

       return area

   

   

class Box (Rectangle):

   

   def __init__(self, length, width, height):

       super().__init__(length, width)

       self.height = height

       

   def volume(self):

       volume = self.length * self.width * self.height

       return volume

   

   def area(self):

       area = 2*(self.length*self.width) + 2*(self.length*self.height) + 2*(self.width*self.height)

       return area

rec_1 = Rectangle(2,4)

box_1 = Box(2,2,6)

print(box_1.length)

print(box_1.area())

   

print(rec_1.length)

print(rec_1.area())

Explanation:

The programming language used is python.

class Rectangle

The class Rectangle is created with attributes length and width.

The class attributes are initialized using the __init__ constructor.

In the rectangle class, a method/function is declared to return the area of the rectangle.

class Box

This class is a child of rectangle and it inherits all its attributes and methods,

It has an additional attribute of depth and its constructor is used to initialize it.

The class contains a volume function, that returns the volume and an override function 'area()' that displaces the area from the parent class.

Finally, some instances of both classes are created.

You might be interested in
What is the first step in planning a multi-table query?
pshichka [43]
When making a multi-table query in Microsoft Office, there must be an assurance that the tables are properly determined in the "Relationships Window." After which, the Microsoft Office's Query Wizard would greatly come in handy in constructing the multi-table query you want to create.
3 0
4 years ago
Assume you're running a query on your orders in the past year. You want to see how many orders were placed after May. What type
vitfil [10]

Your answer is A. Because a query is a question about a an organization to check how it's going


6 0
3 years ago
Define the terms candidate key and primary key. Explain the difference between a primary key and a candidate key.
Shkiper50 [21]

Explanation:

Both Primary Key and Candidate Key are the attributes that are used to access tuples from a table. These (Primary key and Candidate key) are also can be used to create a relationship between two tables.

  • A Candidate Key can be any column or a combination of columns that can qualify as a unique key in the database. Each Candidate Key can qualify as a Primary Key.
  • A Primary Key is a column or a combination of columns that uniquely identify a record. The primary key is a minimal super key, so there is one and only one primary key in any relationship.

<em> The main difference between them is that a primary key is unique but there can be many candidate keys. </em>

I hope you find this information useful and interesting! Good luck!

5 0
4 years ago
Which of the following should businesses and organizations do to promote a safe work environment?
nlexa [21]
<span>The correct answer should be A.Hold managers, supervisors, and employees for meeting their own responsibilities. The policies should be changed more often than every 10 years, and definitely the workers should be involved because the workers know better what is problematic than managers who sit in offices in suits and aren't exposed to dangerous activities.</span>
8 0
3 years ago
Before you start creating a database, you should first use paper to plan, test, and revise. True False
Licemer1 [7]
<span>Before you start creating a database, you should first use paper to plan, test, and revise. True or False?
TRUE</span>
8 0
4 years ago
Read 2 more answers
Other questions:
  • How to write a program that prompts the user to input two POSITIVE numbers — a dividend (numerator) and a divisor (denominator).
    13·1 answer
  • Michelle is a salesperson who is paid on commission. She just sold a customer a very reasonably priced tablet, but only after th
    14·1 answer
  • What are the examples of personal computers ?
    8·1 answer
  • &gt;&gt;&gt; from hog import *
    15·1 answer
  • How is a composite key implemented in a relational database model?
    11·1 answer
  • When you leave your computer for a short period of time, why should you put your computer into Standby mode?
    5·2 answers
  • . The electric company charges according to the following rate schedule: 9 cents per kilowatt-hour (kwh) for the first 300 kwh 8
    12·1 answer
  • &lt;
    6·1 answer
  • Which of these is NOT a reason for an IP Address?
    15·2 answers
  • Type the correct answer in each box. Spell all words correctly.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!