-3

I cant Understand whats the problem with my code I cant figure it out please help me :

    System.out.println("Enter the Radius of the circle: ");
    double radius = input.nextDouble();
    ShapeCircle AndP = new ShapeCircle();
    System.out.println(AndP.Acircle(radius));
    System.out.println(AndP.Pcircle(radius));
    input.close();

I wanted to programme it with abstract

abstract class ShapeCircle{
    public double Acircle(double radius){
        double Ans;
        return Ans = Math.PI * (radius * radius);
    }
    public abstract double Pcircle(double radius);
}

but I can't understand whats the problem,this is my other class :

class shapePcircle extends ShapeCircle{
    public double Pcircle(double radius){
        double Ans;
        return Ans = 2 * Math.PI * radius;
    }
}

the problem is here

    ShapeCircle AndP = new ShapeCircle();

Cannot instantiate the type I don't know why

Atum
  • 1
  • 3
  • What should happen when you call `AndP.Pcircle(2)`? – Pshemo Jun 13 '20 at 18:52
  • It will call your function implementation present in ShapePcircle concrete class – karthik Jun 13 '20 at 18:53
  • An abstract class can not be instantiated. Replace `ShapeCircle AndP = new ShapeCircle();` with e.g. `ShapeCircle AndP = new shapePcircle();`. On a side note, follow [Java naming conventions](https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html) e.g. the class `shapePcircle` should be named as `ShapePcircle`. Similarly, the names of variables and methods in your code are also not compliant with the convention. – Arvind Kumar Avinash Jun 13 '20 at 18:58

1 Answers1

0

Try to instantiate the concrete class instead of the abstract one. In your case

ShapeCircle AndP = new ShapePCircle();

karthik
  • 463
  • 1
  • 6
  • 16