我如何制作一个无参数构造函数来创建(0,0)点?如在Java中的X和Y点? 注意:我知道代码不完整,可能会有一些错误,请帮我构造一下 在此先感谢
public class MyPoint {
public static void main(String[] args) {
private double X;
private double Y;
private String name;
public static int numberOfCreatedPoints;
MyPoint() {
X = 0;
Y = 0;
name = "center";
}
MyPoint (double XCoor, double YCoor, String pointName){
X = xCoor;
Y = yCoor;
name = pointName;
public double getX() {
return X;
}
public double getY() {
return Y;
}
public String name() {
return name;
}
public static getNumberOfCreatedPoints() {
}
}
}
}
答案 0 :(得分:0)
您的课程应该看起来像这样:
public class MyPoint {
private double X;
private double Y;
private String name;
MyPoint() {
X = 0;
Y = 0;
name = "center";
}
//getters and setters ...
public static void main(String[] args) {
}
}