当前位置: 技术问答>java相关
如何编译两个java文件?如sphere.java,createspheres.java
来源: 互联网 发布时间:2015-09-21
本文导语: 我用jdk的javac编译,书上说两个文件只要放在一个目录下就可以自动编译一个文件中使用的其他java类文件。我编译时确出错:cannot resolve symbol 代码如下: Sphere.java ---------------------------------------- class Sphere{ static f...
我用jdk的javac编译,书上说两个文件只要放在一个目录下就可以自动编译一个文件中使用的其他java类文件。我编译时确出错:cannot resolve symbol
代码如下:
Sphere.java
----------------------------------------
class Sphere{
static final double PI = 3.14; //PI
static int count = 0; //Class variable to count object
double radius; //Radius of a sphere
double xCenter; //3D coordinates
double yCenter; //of the center
double zCenter; //of a sphere
//Class constructor
Sphere(double theRadius,double x,double y,double z)
{
radius = theRadius;
xCenter = x;
yCenter = y;
zCenter = z;
++count;
}
//检查有多少个对象产生
static int getCount()
{
return count;
}
double volume()
{
return 4.0/3.0*PI*radius*radius*radius;
}
}
//end
---------------------------------------------------------------------
CreateSpheres.java代码如下
----------------------------------------------------------------------
class CreateSpheres
{
public static void main(String args[])
{
System.out.println("Number of objects = " + Sphere.getCount());
Sphere ball = new Sphere(4.0,0.0,0.0,0.0); //Create a sphere
System.out.println("Number of objects = " + ball.getCount());
Sphere globe = new Shpere(10.0,1.0,1.0,1.0);
System.out.println("Number of objects = " + Sphere.getCount());
System.out.println("Ball volume = " + ball.volume());
System.out.println("Globe voluem = " + globe.volume());
}
}
放在同一目录下,用 javac CreateSpheres.java
那位能指出问题所在?
代码如下:
Sphere.java
----------------------------------------
class Sphere{
static final double PI = 3.14; //PI
static int count = 0; //Class variable to count object
double radius; //Radius of a sphere
double xCenter; //3D coordinates
double yCenter; //of the center
double zCenter; //of a sphere
//Class constructor
Sphere(double theRadius,double x,double y,double z)
{
radius = theRadius;
xCenter = x;
yCenter = y;
zCenter = z;
++count;
}
//检查有多少个对象产生
static int getCount()
{
return count;
}
double volume()
{
return 4.0/3.0*PI*radius*radius*radius;
}
}
//end
---------------------------------------------------------------------
CreateSpheres.java代码如下
----------------------------------------------------------------------
class CreateSpheres
{
public static void main(String args[])
{
System.out.println("Number of objects = " + Sphere.getCount());
Sphere ball = new Sphere(4.0,0.0,0.0,0.0); //Create a sphere
System.out.println("Number of objects = " + ball.getCount());
Sphere globe = new Shpere(10.0,1.0,1.0,1.0);
System.out.println("Number of objects = " + Sphere.getCount());
System.out.println("Ball volume = " + ball.volume());
System.out.println("Globe voluem = " + globe.volume());
}
}
放在同一目录下,用 javac CreateSpheres.java
那位能指出问题所在?
|
哈哈,暴搞笑~~~
你犯了一个很低级的错误~~
Sphere globe = new Shpere(10.0,1.0,1.0,1.0);
应该为:
Sphere globe = new Sphere(10.0,1.0,1.0,1.0);
因为你打错了,当然它就不知道了~~~~
楼上的说的用通配符,也上可以的。
但在这个例子中用不着
你犯了一个很低级的错误~~
Sphere globe = new Shpere(10.0,1.0,1.0,1.0);
应该为:
Sphere globe = new Sphere(10.0,1.0,1.0,1.0);
因为你打错了,当然它就不知道了~~~~
楼上的说的用通配符,也上可以的。
但在这个例子中用不着
|
哪个符号不能解析呀?
试试javac *.java
试试javac *.java
|
用 javac *.java
|
to:huatao (华韬)
建议认真阅读出错信息,就不会犯这样的错误了
建议认真阅读出错信息,就不会犯这样的错误了
|
呵呵,拼写错误