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

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

猜你喜欢

转载自blog.csdn.net/qq_43291759/article/details/124084857