[Solved] GeometricObject and circle class


If you mean why can’t you invoke the getArea() and getPerimeter() methods, it is because they are abstract.

You cannot invoke an abstract method. An abstract method must have an implementation in a concrete class.

Also, you cannot instantiate an interface or an abstract class. You can only instantiate concrete classes (and they may implement an interface or extend an abstract class).

So to use the getArea() and getPerimeter() methods, you need a concrete class that implements them. Such as class might look something like this:

public class ConcreteGeometricObject extends GeometricObject {

    public ConcreteGeometricObject() {
        super();
    }

    public ConcreteGeometricObject(String color, boolean filled) {
        super(color, filled);
    }

    @Override
    public double getArea() {
        double area;
        //implementation code here
        return area;
    }

    @Override
    public double getPerimeter() {
        double perimeter;
        //implementation code here
        return perimeter;
    }
}

And you could use it in manner such as this:

GeometricObject geometricObject = new ConcreteGeometricObject();
//...
double area = geometricObject.getArea();
double perimeter = geometricObject.getPerimeter()

Please read this trail: Lesson: Interfaces and Inheritance

0

solved GeometricObject and circle class