I am confused to as why the Java Point class takes in two int paramaters and the getX() and getY() methods return doubles.
For example I could define a Point
Point p = new Point(4,6);
If I were to call..
p.getX();
It would return 4.0. and if I were to call
p.x;
I would get 4.
Any reason for this?
There are
Point2D.DoubleandPoint2D.Floatclasses that extendPoint2Dwhich is a superclass ofPointand they need to be able to work with floating point values. Note that there is also asetLocation( double, double ).Point2Dis an abstract class that implements the distance calculation for points, andsetLocation,getX, andgetYare its abstract methods, which is why they all usedoublesand whyPointhas to implement them withdoubles in the signature.