0
点赞
收藏
分享

微信扫一扫

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

泠之屋 2022-04-13 阅读 37

原因是在子类继承父类构造函数的时候,子类构造函数使用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 条评论