日期:2014-05-20  浏览次数:20765 次

这个哪里出错了呢 大牛给看看哈 !!!!
class Cycle
{
private double radius;
public Cycle(double radius)
{
this.radius=radius;
}
public Cycle compare(Cycle c)
{
//程序代码
return (this.radius>c.radius) ? this : c ;
}

}
class TD
{
public static void main(String[] args)
{
Cycle c1=new Cycle(1.0);
Cycle c2=new Cycle(2.0);
Cycle c;
c=c1.compare(c2);

if(c==c1)
System.out.println("圆1的面积比较大");
else
System.out.println("圆2的面积比较大");

}
}

------解决方案--------------------
Java code

class Circle {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    public Circle compare(Circle c) {
        // 程序代码
        return (this.radius > c.radius) ? this : c;
    }

}

class TD {
    public static void main(String[] args) {
        Circle c1 = new Circle(1.0);
        Circle c2 = new Circle(2.0);
        Circle c;
        c = c1.compare(c2);

        if (c == c1)
            System.out.println("圆1的面积比较大");
        else
            System.out.println("圆2的面积比较大");

    }
}

------解决方案--------------------
对,不必加其实也可以,目测楼主是不是吧文件名写错了
------解决方案--------------------
我晕,我在 自己的eclipse上面运行,木有错误啊

结果是:圆2的面积比较大

Java code
package com;

public class Cycle {

    private double radius;
    public Cycle(double radius)
    {
    this.radius=radius;    
    }    
    public Cycle compare(Cycle c)
    {
    //程序代码    
    return (this.radius>c.radius) ? this : c ;
    }

}

------解决方案--------------------
探讨

E:\JavaProject\Project>javac De.java

E:\JavaProject\Project>java De
Exception in thread "main" java.lang.NoSuchMethodError: Cycle.compare([LCycle;)D

at De.main(De.java:30)