I have a class shape that has a toString() method. I have another class circle that extends shape. This circle class overrides the inherited toString() method. What I want to do is call the superclass - shape's toString() method from inside the circle's toString() method. The following is what I have done as of now. I thought calling toString() in the toString() of the circle might invoke the inherited toString() but that just goes into an infinite loop.
Shape class:
class shape{
String color;
boolean filled;
shape()
{
color = "green";
filled = true;
}
shape(String color, boolean fill)
{
this.color = color;
this.filled = fill;
}
public String toString()
{
String str = "A Shape with color = " + color + " and filled = " + filled + " .";
return str;
}
}
Circle class:
class circle extends shape
{
double radius;
circle()
{
this.radius = 1.0;
}
public String toString()
{
String str = "A circle with radius " + radius + " and which is a subclass of " + toString();
return str;
}
Please Help!