简体   繁体   English

Java子类没有足够的参数

[英]Java subclass doesn't have enough arguments

I am learning Java OOP reading a book, and it doesn't explain very well the sub classes topic. 我正在学习Java OOP阅读一本书,但它并没有很好地解释子类主题。 I am trying to make a class that solves a system of equations, you can find the code here . 我正在尝试创建一个解决方程组的类,你可以在这里找到代码。

The class sistemi solves systems of 2 equations and the subclass sistemi3eq solves systems with 3 equations. sistemi解决了2个方程的系统,子类sistemi3eq解决了3个方程的系统。 NetBeans is giving me this error: NetBeans给了我这个错误:

在此输入图像描述

I haven't found a lot of documentation. 我还没有找到很多文档。 Do you have any suggestion? 你有什么建议吗? How could I improve my code? 我怎么能改进我的代码?

Your class name don't (and can't) have () so why you do extends sistemi() ? 你的类名没有(也不能)有()所以你为什么extends sistemi()

Just extends sistemi 只是extends sistemi

Your subclass is not actually within your parent class. 您的子类实际上不在您的父类中。 You need to move it within the scope of your parent class. 您需要在父类的范围内移动它。 You can't have two separate pubilc classes in one file. 您不能在一个文件中有两个单独的pubilc类。

Since the second isn't public, you can still use it that way, but you really shouldn't. 由于第二个不公开,你仍然可以这样使用它,但你真的不应该这样做。 You should put it within the sistemi class or in another file. 你应该把它放在sistemi类或另一个文件中。

public class sistemi {
    ...

//this bracket here needs to go at the bottom of the file
//}

    class sistemi3eq extends sistemi {

        ...
    }    
}

I have assigned void at sistemi(double a, double b, double c, double d, double e, double f) and now it works. 我已经在sistemi(double a, double b, double c, double d, double e, double f)分配了void,现在它可以工作了。

public class sistemi {

    private Double x;
    private Double y;

    public void sistemi(double a, double b, double c, double d, double e, double f) {
     //calcolo nella matrice
     double detx = (c*e)-(b*f);
     double dety = (a*f)-(c*d);
     double det = (a*e)-(d*b);

     //calcolo dei risultati x e y del sistema
     if (det != 0) {
      x = detx/det;
      y = dety/det;
     } 
    }

    //funzioni varie
    other code
}

class sistemi3eq extends sistemi {

    private Double x;
    private Double y;
    private Double z;

    //other code    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM