Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Labl, you were provided with a Java class, called Square.java, which contained: Two private instance variables: length of the type double) and color (of

In Labl, you were provided with a Java class, called Square.java, which contained: Two private instance variables: length of the type double) and color (of the type String), with default value of 1.0 and "red", respectively. . Two overloaded constructors - a default constructor with no argument, and a constructor which takes a double argument for length. . Two public methods: getLength() and getArea (), which return the length and area of this instance, respectively. The source codes for square.java is in the file square.java which you submitted. [Task 1] In this task, you will create a subclass called Rectangle which is derived from the superclass Square. Study how the subclass Rectangle invokes the superclass' constructors (via super() and super(length)) and inherits the variables and methods from the superclass Square. You can reuse the Square class that you have created in the previous exercise. Make sure that you keep "Square.java" in the same directory. A partially complete (Skeleton) Rectangle.class code is shown below.

The java code for square.

/** The square class models a square with a length and color.*/public class Square { // Save as "Square.java"// private instance variable, not accessible from outside this class private double length;private String color;// The default constructor with no argument.// It sets the length and color to their default value.public square() {length = 1.0;color = "red";// 2nd constructor with given length, but color default public square(double r) {length = r; color = "red"}// A public method for retrieving the lengthpublic double getlength() {return length;}// A public method for computing the area of square public double getArea() {return length*length;}}

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

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

Convert to rectangular form and graph: r = 3csc .

Answered: 1 week ago

Question

Give an example of a function that is in O(10n), but not in O(2n)

Answered: 1 week ago