import java.lang.Math.hypot;
class CPoint
{
private  double x;
private  double y;
CPoint(double x,double y)
{
this.x = x;
this.y = y;
}
         public void distance(CPoint p)
{
System.out.println("distance"+java.lang.Math.hypot(this.x-p.x,this.y-p.y));
//为什么必须这样调用hypot;明明已经import了啊
}
}
竟然出现了错误
TestCPoint.java:1: 找不到符号
符号: 类 hypot
位置: 类 java.lang.Math
import java.lang.Math.hypot;可是Math中明明有hypot这一个函数啊,在代码中显示调用则成功,真是奇怪?望有人帮忙看看
                     ^

解决方案 »

  1.   

    如果你想使用直接使用类中的静态成员,你可以使用import static(静态导入)代替import;
    或者你可以使用Math.hypot来调用该静态方法。
      

  2.   

    嗯,public static double hypot(double x, double y)是个静态函数,可以这么写import static java.lang.Math.hypot;
    ...
    System.out.println("distance"+hypot(this.x-p.x,this.y-p.y));
      

  3.   

    import java.lang.Math.hypot;
    改为
    import java.lang.Math;System.out.println("distance"+java.lang.Math.hypot(this.x-p.x,this.y-p.y));
    改为
    System.out.println("distance"+Math.hypot(this.x-p.x,this.y-p.y));