到目前为止,我的 Point 类中有这个
//Data
private int x;
private int y;
//Default Constructor
public Point ( )
{
this.x = 0;
this.y = 0;
}
//Parameterized Constructor.
public Point (int newX , int newY)
{
this.x = newX;
this.y = newY;
}
//Copy Constructor.
public Point (Point other)
{
this.x = other.x;
this.y = other.y;
}
我正在尝试创建另一个名为“segment”的类,它将使用我的 Point 类,在该类中我有这个
private Point Point1;
private Point Point2;
public Segment ( )
{
this.Point1 = (0, 0);
this.Point2 = (7, 7);
}
但是,我收到一条错误消息,指出每个 X 点和 Y 点之间应该有一个“)”。
为什么我会收到这个错误?在我的点类中,我对其进行了设置,以便它接受新的 X 和 Y 并将它们设置为新点。因此,在我的分段类中,我传递了 X 和 Y。
请帮助我或澄清我做错了什么。谢谢。
最佳答案
您需要关键字new
和类名。这个
this.Point1 = (0, 0);
this.Point2 = (7, 7);
应该是这样的
this.Point1 = new Point(0, 0);
this.Point2 = new Point(7, 7);
关于java - (Java) 无法设置 X 和 Y 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35401047/