Java Reference
In-Depth Information
else
length = 0;
if (w >= 0)
width = w;
else
width = 0;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public double area()
{
return length * width;
}
public double perimeter()
{
return 2 * (length + width);
}
public String toString()
{
return ("Length = " + length
+ "; Width = " + width + "\n"
+ "Area = " + area());
}
}
Note that the definition of the class RectangleFigure is similar to the definition
of the class Rectangle given previously. The method toString of the class
RectangleFigure , in addition to returning the length and width, also prints the area
of the rectangle.
public class BoxFigure extends RectangleFigure
{
private double height;
public BoxFigure()
{
super ();
height = 0;
}
Search WWH ::




Custom Search