Quote:
quote:Originally posted by lingprash
My question is:
Line(final Point start, final Point end)
{
this.start = new Point(start);
this.end = new Point(end);
}
what happens here???
|
The arguments to the Line constructor are two
Point objects.
These are called
final so it is made impossible to change the value of the argument Point objects.
We use the two arguments to construct two
new Point objects.
Which we store in the
start point and
end point to construct our new Line.
We use
this to refer to the data variables of our Line, instead of the parameter values with the same name, so the compiler will know the difference.
Interesting is:
Here the compiler will not allow you to leave out the
this qualifier, because the parameters are declared final.
Try it out!
An Object type variable is passed by reference. The data members of an Object can be changed when you have a reference to it. Qualifying it as
final prevents changing the original object.
************************************************** ****
Quote:
quote:Originally posted by lingprash
Line(double xStart, double yStart, double xEnd, double yEnd)
{
start = new Point(xStart, yStart); // Create the start point
end = new Point(xEnd, yEnd); // Create the end point
}
what happens here...???
I presume here we get 8 coordinates...
|
No, 4 coordinates, creating two
new Point objects: the
start &
end data members that define our Line.
Another constructor for a Line here, asking for 4 double type arguments.
Interesting is:
The parameters need not be declared
final here. Because
basic type variables (like
double,
char, etc.) are always duplicated when passed to a constructor. So the original
double variables won't be modified, passing them as arguments to the Line constructor.