I wrote an abstract class, Shape.
abstract class Shape
{
String n;
public String getName(String name)
{
n = name;
return n;
}
public abstract double getDimension();
}
I then wrote a subclass of Shape, which is also abstract:
abstract class TwoDimensionalShape extends Shape
{
public double getDimension(byte dimension)
{
dimension = 2;
return dimension; //returns dimension of shapes(subsequent subclasses)
}
public abstract double getPerimeter();
public abstract double getArea();
}
Then, I wrote a subclass of TwoDimensionalShape, called Circle; it is not abstract.
class Circle extends TwoDimensionalShape
{
double a;
String n = "Circle";
//constructor
public Circle(double radius)
{
a = radius;
}
//circumference/perimeter
public double getPerimeter()
{
return 2 * Math.PI * a;
}
//area
public double getArea()
{
return Math.PI * (a * a);
}
}
The error I am getting is: "Circle.java:1: Circle is not abstract and does not override abstract method getDimension() in Shape". Circle inherits getDimension() from TwoDimensionalShape; this overrode the abstract getDimension() in Shape. Thus, I'm not sure how to fix this error; please advise. I am also making a "Driver" class to print the values from getPerimeter() and getArea().

New Topic/Question
Reply



MultiQuote




|