我的程序有问题,我找不到思考的原因。它指向public static void main(String[] args)
其他任何地方的行,无法弄清楚:(尝试检查大括号,如果我不小心错过了一两个但仍然没有,它不是接口实现,所以我不必设置每个方法在实现中公开抽象类...
abstract class Shape {
private String name;
Shape(String name0) {name = name0;}
abstract double area();
abstract double perim();
void put() {
System.out.println(name + " with area " + area()+ " and perimeter " + perim());
}
}
class Circle extends Shape{
private double r;
Circle(String name0, double inR) {
super(name0);
r = inR;
}
double area() {
return (Math.sqrt(r)*Math.PI);
}
double perim() {
return 2*(Math.PI * r);
}
}
class Rectangle extends Shape{
private double a,b;
Rectangle(String name0, double a0, double b0) {
super(name0);
a=a0; b=b0;
}
double area() {
return (a*b);
}
double perim() {
return 2*(a+b);
}
}
}
class TestClass {
public static void main(String args[]) {
Shape[] figures = {new Rectangle("Rectangle", 2.0, 3.0), new Rectangle("Square", 4.0, 4.0), new Circle("Circle", 2.0)};
for (Shape s: figures)
s.put();
}
}