Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:类student中的构造函数student不能应用于给定类型;超级(姓名、注册);_Javascript_Java_Inheritance_Constructor - Fatal编程技术网

Javascript 错误:类student中的构造函数student不能应用于给定类型;超级(姓名、注册);

Javascript 错误:类student中的构造函数student不能应用于给定类型;超级(姓名、注册);,javascript,java,inheritance,constructor,Javascript,Java,Inheritance,Constructor,我一开始就宣布了超级右翼。但它仍然显示了错误,它不是。此外,父类中的构造函数具有与“super()”中编写的构造函数相同的参数。但它仍然说参数不匹配 import java.io.*; import java.util.Scanner; class student { public String name; public int enroll; public void student(String name, i

我一开始就宣布了超级右翼。但它仍然显示了错误,它不是。此外,父类中的构造函数具有与“super()”中编写的构造函数相同的参数。但它仍然说参数不匹配

 import java.io.*;
    import java.util.Scanner;
    
     class student
    {
      public String name;
      public int enroll;
    
      public void student(String name, int enroll)
      {
        this.name=name;
        this.enroll=enroll;
      }
    }
    class Science extends student
    {
      int phy;
      int chem;
      int maths;
      public void Science(String name, int enroll, int phy, int chem, int maths)
      {
        super(name,enroll);
        this.phy=phy;
        this.chem=chem;
        this.maths=maths;
      }
    }
    class Arts extends student
    {
      int eng;
      int hist;
      int eco;
      public void Arts(String name, int enroll, int eng, int hist, int eco)
      {
        super(name,enroll);
        this.eng=eng;
        this.hist=hist;
        this.eco=eco;
      }
      
    }
    public class asd
    {
      //enter code here
      public static void main(String[] args)  throws IOException
      {
        //enter code here
       } 
      
    }

正如注释中指出的,您需要从中删除
void
,因为它们没有任何显式的返回类型。你可以检查这个答案来找出答案

因此,您当前的构造函数如下所示:

public void student(字符串名称,整数注册)
{
this.name=name;
this.enroll=注册;
}
改为如下所示,类名也应以大写字母开头,如下所示:


正如@OH GOD SPIDERS所提到的,void返回类型使其成为方法而不是构造函数,并且编译器正在检查super(name,enroll)与默认构造函数super(),删除返回类型应该可以解决它

public void student
class Student {

  public Student(String name, int enroll)
  {
    this.name=name;
    this.enroll=enroll;
  }