我收到一个错误,说类中的方法无法应用于给定的类型


I'm new to Java inheritance. I am getting this error

java:21:error:类CircleArea中的方法getRadius不能应用于给定的类型;return(2Math.PIgetRadius((height(+(2super.findArea(((;^

这是我的超高级代码

import java.text.DecimalFormat;
public class CircleArea{
private double radius;
public CircleArea(){ //default
radius = 10.22;
}
public CircleArea(double r){ //constructor with value
radius = r;
}
public double getRadius(){
return radius;
}
public double findArea(){
return Math.PI*radius*radius;
}
public String toString(){
DecimalFormat df = new DecimalFormat("###,###,##");
return "nThe radius of the Circle is: "+radius
+   "nThe area of the Circle is: "+df.format(findArea());
}
}

这是的子类

import java.text.DecimalFormat; 
public class CylinderArea extends CircleArea{
private double height;
public CylinderArea(){
super();
height = 22.50;
}
public CylinderArea(double r, double h){
super(r);
height = h;
}
public double getHeight(){
return height;
}
public double findArea(){
return (2*Math.PI*getRadius()*height)+(2*super.findArea());
}
public String toString(){
DecimalFormat df = new DecimalFormat("###,###.##");
return "nThe radius of the Cylinder is: "+getRadius()
+   "nThe area of the Cylinder is: "+df.format(findArea()); 
}
}

这是主要的

public class TestInheritance{
public static void main(String []args){
CircleArea c1 = new CircleArea();
CylinderArea cy1 = new CylinderArea();
System.out.println(c1);
System.out.println(cy1);
}
}

有人能帮忙吗?

我在ide(Eclipse(中尝试了相同的代码,没有得到任何错误。

给定代码输出

相关内容

最新更新