【发布时间】:2020-10-09 07:18:57
【问题描述】:
我有这个类,它基本上代表 X-Y 平面上的一个点,并且有这个函数来计算两个点对象之间的距离:
double dist(2DPoint p){
return Math.sqrt(Math.pow(x-p.x, 2) + Math.pow(y-p.y, 2));
}
我现在想在 3DPoint 类中创建一个表示空间点的类。我想继承 2d Point 并创建一个计算两个 3d 点之间距离的函数。
我想这样做,这样我就可以像这样使用以前的功能:
double dist(3DPoint p)
{
return Math.sqrt(Math.pow(z - p.z, 2) + /*Square of dist between X,Y s of the two 3d pts using the dist function from 2DPoint*/);
}
【问题讨论】:
-
你可以调用 super.dist()
标签: java inheritance scope cartesian