如何在一个类中调用另一个类?
类一:
class Sphere
{
static final double PI=3.14;
static int count = 0;
double radius;
double xCenter;
double yCenter;
double zCenter;
Sphere (double theRadius,double x,double y,double z)
{
radius=theRadius;
xCenter=x;
yCenter=y;
zCenter=z;
}
static int getCount()
{
return count;
}
double volume()
{
return 4.0/3.0*PI*radius*radius*radius;
}
}
类二:调用类一。
class Create
{ 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);
System.out.println("Number of objects="+Sphere.getCount());
Sphere globe =new Sphere(12,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 volume="+globe.volume());
}
}
编译出现不能解析Sphere;