本文介绍了获得Point对象值的两种方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么通过使用方法并引用值从java.awt.Point类中获取x和y值?
How come you can get the x and y values from a java.awt.Point class by using a method and referencing the value?
Point p = new Point(10,20);
int x0 = p.getX();
int y0 = p.getY();
int x1 = p.x;
int y1 = p.y;
System.out.println(x0+"=="+x1+"and"+y0+"=="+y1);
创建此类的人是否忘记将x和y设为私有?
Did the people who made this class forget to make x and y private?
推荐答案
查看 javadoc ,这些似乎返回不同的类型. p.x
返回int
,而p.getX()
返回double
.
Looking at the javadoc, these seem to return different types. p.x
returns an int
while p.getX()
returns a double
.
Point
的源代码显示如下:
public int x;
//...
public double getX() {
return x;
}
所以看起来这是唯一的目的. getX()
是获取double
坐标的一种更方便的方法.
So it looks like that's its only purpose. getX()
is a more convenient way to get the coordinates as a double
.
这篇关于获得Point对象值的两种方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!