java中无法将类Point中的构造器Point应用到给定类型
publicclassPoint{publicdoubledistance(){returnMath.sqrt(x*x+y*y);}staticvoidmain(Stri...
public class Point{ public double distance(){ return Math.sqrt(x*x + y*y); } static void main(String args[]){ Point p = new Point(1,1); System.out.println("p.distance()= " + p.distance()); p = new Point3d(1,1,1); System.out.println("p.distance()= " + p.distance()); } } class Point3d extends Point{ public double distance(){ return Math.sqrt(x*x + y*y + z*z); } }
展开
展开全部
public class Point {
int x,y;
public Point(int x,int y){
this.x = x;
this.y = y;
}
public double distance() {
return Math.sqrt(x * x + y * y);
}
public static void main(String args[]) {
Point p = new Point(1, 1);
System.out.println("p.distance()= " + p.distance());
p = new Point3d(1, 1, 1);
System.out.println("p.distance()= " + p.distance());
}
}
class Point3d extends Point {
int z;
public Point3d(int x, int y,int z) {
super(x, y);
this.z = z;
}
public double distance() {
return Math.sqrt(x * x + y * y + z * z);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询