Java Point, difference between getX() and point.x

后端 未结 1 958
南笙
南笙 2021-01-12 15:25

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



        
1条回答
  •  迷失自我
    2021-01-12 15:57

    There are Point2D.Double and Point2D.Float classes that extend Point2D which is a superclass of Point and they need to be able to work with floating point values. Note that there is also a setLocation( double, double ).

    Point2D is an abstract class that implements the distance calculation for points, and setLocation, getX, and getY are its abstract methods, which is why they all use doubles and why Point has to implement them with doubles in the signature.

    0 讨论(0)
提交回复
热议问题