Java有关类与对象

求两点之间的距离,见如下代码
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Point originPoint = new Point();
Scanner scanner = new Scanner(System.in);
double x = scanner.nextDouble();
double y = scanner.nextDouble();
Point point = new Point(x,y);
System.out.println("The point's x is "+point.getX()+" and point's y is "+point.getY());
System.out.printf("The distance from point to origin is:%.3f%n",point.calDistance(originPoint));
point.moveTo(20,10);
System.out.printf("After move,the distance from point to origin is:%.3f ",point.calDistance(originPoint));
}
}

public class Point {
private double x;
private double y;
public Point(){
}
public Point(double x,double y){
this.x=x;
this.y=y;
}

public double getX() {
    return x;
}

public double getY() {
    return y;
}
public void moveTo(double x,double y){
    this.x = x;
    this.y = y;
}
public double calDistance(Point target){
    double x1 = this.x- target.getX();
    double y1 = this.y- target.getY();
    return Math.pow(x1*x1+y1*y1,0.5);
}

}
问题:1.在Point类中的calDistance方法形参中target和方法中的target.getX()的target是什么意思,以及target.getX()是什么意思,这是在调用哪里的x,
2. System.out.printf("The distance from point to origin is:%.3f%n",point.calDistance(originPoint));该句的实参为什么是originPoint,这是什么意思,是传入了几个参数?

这两个target是同一个东西,就是Point类的一个对象
target.getX() 就是获得target这个对象的x属性值
originPoint 是个Point类的对象,在main函数中,Point originPoint = new Point();定义的类对象啊。

point.calDistance(originPoint) 是调用point类对象的calDistance函数,计算point对象与originPoint对象的距离,calDistance函数两个点之间的距离值,然后用printf函数输出,这个距离值将替换%.3f所在的位置

1、calDistance方法形参中target表示传进来的一个 Point对象, 方法中的target.getX()指的就是获取传进来的对象的X属性
2、originPoint 是个对象,就传进来了一个参数,只不过参数是一个对象

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632