有相互依赖的源文件用eclipse编译成功,单独编译失败,请大家帮忙指点一下,谢谢!
其中Example5_10.java保存在当前目录,Geometry.java,Pillar.java,Rectangle.java保存在当前目录下的com/yaya/目录下
问题是:我不用ecilpse,用手动javac去编译Geometry.java,Pillar.java,Rectangle.java,请问如何的一个编译顺序才可行呢?
我首先编译成功了Geometry.java,D:\workspace\Pillar\src\com\yaya>javac -encoding utf-8 Geometry.java
但是,Pillar.java,Rectangle.java都编译失败,但是用eclipse是编译成功的,请问这是为什么,该怎么处理?非常感谢!
D:\workspace\Pillar\src\com\yaya>javac -encoding utf-8 Pillar.java
Pillar.java:33: 找不到符号
符号: 类 Geometry
位置: 类 com.yaya.Pillar
Geometry bottom;
^
Pillar.java:39: 找不到符号
符号: 类 Geometry
位置: 类 com.yaya.Pillar
public Pillar(Geometry bottom, double height){
^
Pillar.java:44: 找不到符号
符号: 类 Geometry
位置: 类 com.yaya.Pillar
public void setBottom(Geometry bottom){
^
3 错误
D:\workspace\Pillar\src\com\yaya>javac -encoding utf-8 Rectangle.java
Rectangle.java:5: 找不到符号
符号: 类 Geometry
public class Rectangle extends Geometry{
^
1 错误
//1. Geometry.java
package com.yaya;
/*
计算几何图形的面积
*/
public abstract class Geometry{
public abstract double getArea();
}
//2. Pillar.java
package com.yaya;
/*
设计一个Pillar类,通过Pillar类创建的对象计算各种柱体的体积
*/
public class Pillar{
Geometry bottom;
double height;
Pillar(){
}
public Pillar(Geometry bottom, double height){
this.bottom=bottom;
this.height=height;
}
public void setBottom(Geometry bottom){
this.bottom=bottom;
}
public double getVolume(){
return bottom.getArea()*height;
}
}
//3、Rectangle.java
package com.yaya;
/*
计算长方形的面积
*/
public class Rectangle extends Geometry{
double length;
double width;
Rectangle(){
}
public Rectangle(double length, double width){
this.length=length;
this.width=width;
}
public double getArea(){
return length*width;
}
}
//4、Example5_10.java
import com.yaya.*;
public class Example5_10{
public static void main(String args[]){
Pillar pillar;
Geometry tuxing;
tuxing=new Rectangle(2,7);
pillar=new Pillar(tuxing, 3);
System.out.println("bottom is Rectangle, the Volume="+pillar.getVolume());
}
}
------解决方案--------------------