其中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());
}
}
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());
}
}
没记错的话应该是这样
javac -encoding utf-8 Geometry.java;Pillar.java;Rectangle.java
如果Geometry.class就在当前目录
你试试
javac -encoding utf-8 -classpath Geometry.class Pillar.java
javac -encoding utf-8 Geometry.java Pillar.java Rectangle.java
谢谢 果真可以了
编译的原理上能否帮忙介绍一下啊,照理说Geometry.java编译成功后生成Geometry.class字节码,后面依赖的类再编译应该可以的啊?
应该是这样写的,你试试
javac -encoding utf-8 -classpath Geometry.class Pillar.java
因为你不指明位置,它还是不知道去哪找Geometry.class