Square
Write the class Square
which is derived from the Shape
class shown below. A Square
is a Shape
that has 4 equal sides.
Include a constructor that will allow for the creation of aSquare
object with a given side length as shown below.
Square mySquare = new Square(3);
//creates a square with a side length of 3
The line of code above shows the creation of a Square object which points to the
constructor that you need to complete! This means that your constructor for Square
should have 1 parameter. What is this parameter for?
This class should override the getArea()
and getPerimeter()
methods from its parent class.
public class Shape{
public double getArea(){
return 0.0;
}
public double getPerimeter(){
return 0.0;
}
}
Type your solution
Skills Practiced:
3.B
4.A
4.B
1.C
Saved
Saved