程序报错找不到合适的构造器请问是什么原因?怎么解决?
class Sphere{
static final double PI=3.14;
static int count=0;
double radius;
double xCenter;
double yCenter;
double zCenter;
// Construct a unit sphere at a point
Sphere(double x,double y,double z){
xCenter=x;
yCenter=y;
zCenter=z;
radius=1.0;
++count; // Update object count
}
static int getCount(){
return count;
}
//Construct a unit sphere at the origin
Sphere() {
xCenter = 4.0;
yCenter = 0.0;
zCenter = 0.0;
radius = 1.0;
++count; // Update object count
}
// Instance method to calculate volume
double volume(){
return 4.0/3.0*PI*radius*radius*radius;
}
}
public class CreateSphere {
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
Sphere globe=new Sphere(12.0,1.0,1.0,1.0); // Create a sphere
System .out .println("Number of objects="+Sphere.getCount());
System .out .println("Number of objects="+ball.getCount());
Sphere eightBall=new Sphere(10.0,10.0,0.0);
Sphere oddBall=new Sphere();
System .out .println("Number of objects="+Sphere.getCount());
// Output the volume of each sphere
System .out .println("ball volume="+ball.volume());
System .out .println("globe volume="+globe.volume());
System .out .println("eightBall volume="+eightBall.volume());
System .out .println("oddBall volume="+oddBall.volume());
}
}
Error:(35, 21) java: 对于Sphere(double,double,double,double), 找不到合适的构造器
构造器 Sphere.Sphere(double,double,double)不适用
(实际参数列表和形式参数列表长度不同)
构造器 Sphere.Sphere()不适用
(实际参数列表和形式参数列表长度不同)
Error:(36, 22) java: 对于Sphere(double,double,double,double), 找不到合适的构造器
构造器 Sphere.Sphere(double,double,double)不适用
(实际参数列表和形式参数列表长度不同)
构造器 Sphere.Sphere()不适用
(实际参数列表和形式参数列表长度不同)