Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!