不知道为什么我写的这个重载方法用不了,求解惑
代码和报错原因如下:
package com.wkcto;
import java.lang.Math;
class Point2D{
int x,y;
//构造方法
public Point2D(int x,int y){
this.x=x;
this.y=y;
}
public Point2D(){};
}
class Point3D extends Point2D{
int z;
public Point3D(int x,int y,int z){
super(x,y);
this.z=z;
}
//构造方法
public Point3D(Point2D p,int z){
x=p.x;
y=p.y;
this.z=z;
}
}
public class experiment7_2 {
public static void main(String[] args) {
Point2D p2d1=new Point2D(3,4);
Point2D p2d2=new Point2D(5,5);
System.out.println("平面两点的距离为:"+ Sqrt(p2d1,p2d2));
Point3D p3d1=new Point3D(3,4,5);
Point3D p3d2=new Point3D(p2d2,5);
Sqrt(p3d1,p3d2);
}
double Sqrt(Point2D a,Point2D b){
int x1=a.x-b.x;
int y1=a.y-b.y;
double n=x1*x1+y1*y1;
return Math.sqrt(n);
}
double Sqrt(Point3D a,Point3D b) {
int x1 = a.x - b.x;
int y1 = a.y - b.y;
int z1 = a.z - b.z;
double n = x1 * x1 + y1 * y1 + z1 * z1;
return Math.sqrt(n);
}
}