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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started