Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer the following questions based on the following Rectangle class: public class Rectangle { private int length; private int width; public Rectangle(int length, int width)

Answer the following questions based on the following Rectangle class:

public class Rectangle

{

private int length;

private int width;

public Rectangle(int length, int width)

{

this.length = length;

this.width = width;

}

public int area()

{

return length * width;

}

)

a) Write a class Cube:

-It should inherit from Rectangle

-It should have one instance variable for height

-It should have one constructor that takes 3 parameters (length, width, and height)

-You should NOT include any other methods or instance variables

b) Write the toString method for Rectangle if length is 3 and width is 2, it should return 3 x 2

c) Write a volume method for Cube that uses the area method in the Rectangle class

d) Explain why I made the instance variables (length and width) in Rectangle private instead of public

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago