package case3; public class superTest { public static void main(String[] args) { // 实例化一个Student类的对象s,为Student对象s中的school赋值,打印输出信息 /********* begin *********/ Student s = new Student("张三",18,"哈佛大学"); s.print(); /********* end *********/ } } class Person { /********* begin *********/ String name; int age; public void Person(String name,int age){ this.name=name; this.age=age; } /********* end *********/ } class Student extends Person { /********* begin *********/ String school; public void Student(String name,int age,String school){ super.Person(name,age); this.school=school; } void print(){ System.out.println("姓名:"+name+"年龄:"+age+"学校:"+school); } /********* end *********/ }src/case3/superTest.java:7: error: constructor Student in class Student cannot be applied to given types; Student s = new Student("张三",18,"哈佛大学"); ^ required: no arguments found: String,int,String reason: actual and formal argument lists differ in length报错这个,请在不要改变我原有程序架构的条件下修改我的程序
时间: 2023-07-18 08:45:27 浏览: 149
使用 Jest 和 Supertest 进行接口端点测试实例详解
请修改以下代码:
```
public void Person(String name,int age){
this.name=name;
this.age=age;
}
```
修改为:
```
public Person(String name,int age){
this.name=name;
this.age=age;
}
```
```
public void Student(String name,int age,String school){
super.Person(name,age);
this.school=school;
}
```
修改为:
```
public Student(String name,int age,String school){
super(name,age);
this.school=school;
}
```
在Java中,构造函数没有返回值类型,因此在定义构造函数时不需要声明void。在调用超类的构造函数时,应使用super关键字,并传递相应的参数。
阅读全文