无法实例化类型(抽象)
Cannot instantiate the type (abstract)
我无法理解我的代码有什么问题我无法弄清楚请帮助我:
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();
我想用抽象来编程
abstract class ShapeCircle{
public double Acircle(double radius){
double Ans;
return Ans = Math.PI * (radius * radius);
}
public abstract double Pcircle(double radius);
}
但我不明白这是什么问题,这是我的另一个 class :
class shapePcircle extends ShapeCircle{
public double Pcircle(double radius){
double Ans;
return Ans = 2 * Math.PI * radius;
}
}
问题出在这里
ShapeCircle AndP = new ShapeCircle();
无法实例化类型
不知道为什么
尝试实例化具体的 class 而不是抽象的实例。
在你的情况下
ShapeCircle AndP = new ShapePCircle();
我无法理解我的代码有什么问题我无法弄清楚请帮助我:
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();
我想用抽象来编程
abstract class ShapeCircle{
public double Acircle(double radius){
double Ans;
return Ans = Math.PI * (radius * radius);
}
public abstract double Pcircle(double radius);
}
但我不明白这是什么问题,这是我的另一个 class :
class shapePcircle extends ShapeCircle{
public double Pcircle(double radius){
double Ans;
return Ans = 2 * Math.PI * radius;
}
}
问题出在这里
ShapeCircle AndP = new ShapeCircle();
无法实例化类型 不知道为什么
尝试实例化具体的 class 而不是抽象的实例。 在你的情况下
ShapeCircle AndP = new ShapePCircle();