Write a class called square that is a child class of


Q1. Write a class called Square that is a child class of Rectangle. A square is a rectangle with equal sides. It should inherit the perimeter() and area() methods. It should also inherit the get and set methods for each attribute, if that is appropriate. The Square class should override the getType() method from the superclass so that it returns or outputs "Square."

Q2. Write a class called TestDriver that demonstrates all of the code in your Rectangle class and your Square class. The TestDriver class should do the following:
Create a Rectangle and a Square.
Go into a loop where it asks the user if they want a Rectangle or Square.
Read user answer.
If user wants to quit, then exit the program.
If user wants a Rectangle, ask user for width and length. If user wants a Square, ask user for the length of one side.
Display the type (Rectangle or Square), the length, width, area, and perimeter.
Return to Step 2.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write a class called square that is a child class of
Reference No:- TGS02387287

Now Priced at $10 (50% Discount)

Recommended (95%)

Rated (4.7/5)