Reference example in chapter 5 pages 188 and 190.
If I strip down the code for the Point class to:
Code:
public class Point {
double x;
double y;
public Point(double xVal, double yVal) {
x = xVal;
y = yVal;
}
public Point(Point oldPoint) {
x = oldPoint.x;
y = oldPoint.y;
}
}
And strip the code of the Line class down to:
Code:
public class Line {
Point start;
Point end;
public Line(Point start, Point end) {
this.start = new Point(start);
this.end = new Point(end);
}
}
And compile the Line.java file, both the Line and Point source files compile. But if I remove this method:
Code:
public Point(Point oldPoint) {
x = oldPoint.x;
y = oldPoint.y;
}
from the Point class source file, the Point source file compiles but the Line source file won't. The compiler says:
Line.java:6: error: constructor Point in class Point cannot be applied to given
types;
this.start = new Point(start);
^
required: double,double
found: Point
reason: actual and formal argument lists differ in length
Line.java:7: error: constructor Point in class Point cannot be applied to given
types;
this.end = new Point(end);
^
required: double,double
found: Point
reason: actual and formal argument lists differ in length
I understand the error messages but not why there is are errors. Just wondering what it is I am missing that is causing me to not understand what is wrong with the code this way.