亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

類不是抽象的,并且不重寫抽象方法錯誤

類不是抽象的,并且不重寫抽象方法錯誤

滄海一幻覺 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 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號