javascript - 错误:学生班中的构造函数学生不能应用于给定类型;超级(姓名,注册);
问题描述
我一开始就宣布了超级权利。但它仍然显示它不是的错误。父类中的构造函数也与“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(String name, int enroll)
{
this.name=name;
this.enroll=enroll;
}
应该看起来像这样,类名也应该按照标准 java 约定以大写字母开头:
class Student {
public Student(String name, int enroll)
{
this.name=name;
this.enroll=enroll;
}
推荐阅读
- php - 对对象数组使用 $casts
- reactjs - 如何向我构建的这个 simplepeer webrtc 应用程序添加静音/取消静音和视频开/关按钮?
- mysql - MYSQL:获取倒数第二个最大值行,但未显示某些日期。为什么?
- powershell - Powershell 发送 EMAIL 附加最后修改的文件详细信息?
- javascript - Github App 身份验证未显示登录
- function - 我无法在 webapp 的服务器端代码中调用函数
- java - isAlpha(str) 是将波斯语转换为 Unicode 字符并返回 true 的方法
- javascript - 我正在使用 for 循环和附加子级为 js 制作日历。但是,当我运行代码时,它仅附加在循环的最后一次迭代中
- apache-spark - 当我们提交 Spark 应用程序时,ApplicationSubmissionContext 到底在什么阶段被创建并提交给 YARN 的 RM
- c - c中的管道写入和读取错误:程序冻结