Call to ‘super()‘ must be first statement in constructor body

泠之屋

关注

阅读 59

2022-04-13

原因是在子类继承父类构造函数的时候,子类构造函数使用void修饰返回值了。

在这里插入代码片

在这里插入图片描述
正确的应该去掉void:

package Student;

import myutils.*;

public class Student extends Common {

    public Student() {
    }

    public  Student(String name, int age, int money) {
        super(name, age, money);
    }

    public void getSomeMoney(int money) {
        int hasMoney = super.getMoney();
        super.setMoney(hasMoney + money);
    }
}

精彩评论(0)

0 0 举报