日期:2014-05-20 浏览次数:20761 次
public class RoundArea extends Area{ double roundarea , width; double area(double width){ roundarea=Math.PI*width*width; return roundarea; } } ....... RoundArea c=new RoundArea (); c.area(1.0);//根据你在RoundArea定义的方法需要你传入一个double 类型的参数 System.out.println("圆的面积是"+c); //这样就出来结果了 //矩形类似的
------解决方案--------------------
Area.java
public abstract class Area {
public double area(double x){
return Math.PI * x * x ;
}
public double area(double x, double y ){
return x * y ;
}
}
RoundArea.java
public class RoundArea extends Area{
//private double roundarea , width;
/**
public double area(double width){
roundarea=Math.PI*width*width;
return roundarea;
}
*/
}
RectArea.java
public class RectArea extends Area{
//private double rectarea ,length, width;
/**
public double area(double length,double width){
rectarea=length*width;
return rectarea;
}
*/
}
ImpleArea.java
public class ImpleArea{
private double length,width;
//保留默认构造函数
public ImpleArea(){
}
//定义一个构造函数 ,初始化私有变量
public ImpleArea(double length, double width){
this.length = length ;
this.width = width ;
}
public double getx(){
System.out.println("length="+length);
System.out.println("length="+width);
//到底是想返回 length 还是 width 还是 length * width ,看你的方法名定义getx()应该是返回 length
return length;
//return width;
}
}
Test.java
public class Test{
public static void main(String[] args) {
// TODO Auto-generated method stub
Area c = new RoundArea() ;
double dc = c.area(10.1) ; // 你定义的area方法是有一个double参数的,调用的时候需要放入参数啊