日期:2014-05-20  浏览次数:20768 次

小弟请求关于java包的问题
我想把shape接口,Circle类,Rectangle类定义在shapepackage包中,但用 javac -d . Rectangle.java 出现了问题,小弟刚学JAVA不久 请帮帮忙看看啊,谢谢拉
代码如下:
package shapepackage;
interface shap{
final float PI=3.1415926f;
public double area(double r);
public double area(double w,double h);
public double peri(double r);
public double peri(double w,double h);
public void showArea();
public void showPeri();
}
abstract class Circle implements shap{
public double area(double r){
return PI*r*r;
}
public double peri(double r){
return 2*PI*r;
}

public void showArea(){
System.out.println("圆的面积为:"+area(double r));
}

public void showPeri(){
System.out.println("圆的周长为: "+area(double r));
}
}
public abstract class Rectangle implements shap{
public double area(double w,double h){
return w*h;
}
public double peri(double w,double h){
return 2*(w+h);
}
public void showArea(){
System.out.println("矩形的面积为:"+area(double w,double h));
}
public void showPeri(){
System.out.println("矩形的周长为:"+peri(double w,double h));
}
}

下面是我编译是出的错误:
D:\my java\第五章\build\classes>javac -d . Rectangle.java
Rectangle.java:20: 需要 ".class"
  System.out.println("圆的面积为:"+area(double r));
  ^
Rectangle.java:20: 需要 ';'
  System.out.println("圆的面积为:"+area(double r));
  ^
Rectangle.java:24: 需要 ".class"
  System.out.println("圆的周长为: "+area(double r));
  ^
Rectangle.java:24: 需要 ';'
  System.out.println("圆的周长为: "+area(double r));
  ^
Rectangle.java:35: 需要 ".class"
  System.out.println("矩形的面积为:"+area(double w,double h));
  ^
Rectangle.java:35: 需要 ".class"
  System.out.println("矩形的面积为:"+area(double w,double h));
  ^
Rectangle.java:35: 需要 ';'
  System.out.println("矩形的面积为:"+area(double w,double h));
  ^
Rectangle.java:35: 非法的表达式开始
  System.out.println("矩形的面积为:"+area(double w,double h));
  ^
Rectangle.java:38: 需要 ".class"
  System.out.println("矩形的周长为:"+peri(double w,double h));
  ^
Rectangle.java:38: 需要 ".class"
  System.out.println("矩形的周长为:"+peri(double w,double h));
  ^
Rectangle.java:38: 需要 ';'
  System.out.println("矩形的周长为:"+peri(double w,double h));
  ^
Rectangle.java:38: 非法的表达式开始
  System.out.println("矩形的周长为:"+peri(double w,double h));
  ^
12 错误

D:\my java\第五章\build\classes>

------解决方案--------------------
探讨
public void showArea(){
System.out.println("圆的面积为:"+area(double r));
}