我有一个问题。第一次,我在JAVA中使用多个类。我这样做有些麻烦。我创建了一个班级,该班级将从另一个班级进行调用。我想创建一个Coordinate
类型,顾名思义,它保存坐标。然后,我想移动这些坐标。到目前为止,代码如下:
public class Coordinate {
double x;
double y;
Coordinate(){
x=0;
y=0;
}
public Coordinate(int x,int y){
this.x = x;
this.y = y;
System.out.print(x);//TO TEST WHETHER IT DOES SOMETHING
}
Coordinate shiftCoordinate(int z,int w){
this.x = x + z;
this.y = y+ w;
return new Coordinate(x,y);//ERROR: The constructor Coordinate(double,double) is undefined
}
}
在指出的地方抛出错误。我不明白这个错误。在我的“主要”课程中,我做了以下事情:
void start() {
Coordinate coordinate = new Coordinate();
coordinate.x=3;
coordinate.y=4;
}
我希望它能打印3
,但不会。我在哪里错了?