为了账号安全,请及时绑定邮箱和手机立即绑定

类不是抽象的,并且不重写抽象方法错误

类不是抽象的,并且不重写抽象方法错误

沧海一幻觉 2023-08-04 15:52:52
我一直在开发一个程序,可以为学校找到多项式的根,并执行各种其他多项式相关的操作,例如将它们加在一起或查找给定 x 的多项式的值。虽然我制作的其他两个类工作正常(它们找到了 sin 和 cos 函数的根),但我的 FuncPoly 类似乎与我的评估方法以某种方式发生冲突,并且不想继承它。这是我的确切错误消息:.\FuncPoly.java:1: 错误:FuncPoly 不是抽象的,并且不会重写 Function public class FuncPoly extends Function{ 中的抽象方法评估(double)我尝试稍微摆弄评估方法并尝试添加一些覆盖,但它对我没有多大帮助。我需要帮助找出导致此错误的原因;也许它与我的构造函数有关?感谢您的阅读和帮助!代码如下;里面有很多内容,但我认为其中大部分与问题无关。 public abstract double evaluate(double x); //Basically just a filler for SinFunc and CosFunc    public double findRoot(double a, double b, double epsilon){        double x = ( a + b ) / 2;        if (Math.abs( a - x) <= epsilon){            return x;        }else if (evaluate(x)*evaluate(a) >= 0){            return findRoot(x, b, epsilon);        }else{            return findRoot(a, x, epsilon);        }    }    public static void main(String[] args){        //Tests SinFunc and CosFunc        SinFunc q = new SinFunc();        CosFunc w = new CosFunc();        System.out.println("The root of sin(x) with the numbers entered with the given epsilon is: " + q.findRoot(3,4,.00000001));        System.out.println("The root of cos(x) with the numbers entered with the given epsilon is: " + w.findRoot(1,3,.00000001));        //Tests the FuncPoly stuff        int[] test1 = {1,0,-3};        int[] test2 = {1,-1,-2};        FuncPoly poly1 = new FuncPoly(test1);        FuncPoly poly2 = new FuncPoly(test2);        System.out.println("The root of x^2 + (-3) is" + poly1.findRoot(0,10,.00000001));    }}____________________________public class FuncPoly extends Function{    public int coefficients[];    public FuncPoly(int[] coefficients){        //Constructor        this.coefficients = coefficients;    }    public int degree(){        //Finds the highest power by finding the location of the last number in the array.        return this.coefficients.length - 1;    }
查看完整描述

1 回答

?
慕斯王

TA贡献1864条经验 获得超2个赞

据我所知,您的value()方法FuncPoly需要重命名为evaluate()才能成功实现类中的抽象evaluate()方法Function



查看完整回答
反对 回复 2023-08-04
  • 1 回答
  • 0 关注
  • 71 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信