我收到一个错误说:
src/Circle.java:5: error: call to super must be first statement in constructor
{super(c);
即使我打电话super();
给我的第一个构造函数声明。
public class Circle extends AbstractShape
{
private int radius;
void Circle(String c, int r)
{super(c);
this.radius = r;
}
public double getPerimeter()
{
return (2*3.14*this.radius);
}
public double getArea()
{
return (3.14*this.radius*this.radius);
}
public String toString()
{
return this.colour;
}
}
发布于 2019-06-24 16:07:33
构造函数没有返回类型,甚至没有void
:
void Circle(String c, int r)
^^^^ remove that bit
https://stackoverflow.com/questions/-100007043
复制相似问题