获得Point对象值的两种方法? [英] Two ways to get value of Point object?

查看:115
本文介绍了获得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?

推荐答案

查看

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对象值的两种方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆