调用super必须是构造函数中的第一个语句,但它是 [英] Call to super must be first statement in the constructor, but it is

查看:154
本文介绍了调用super必须是构造函数中的第一个语句,但它是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直收到错误,说调用super必须是构造函数中的第一个语句。

I keep getting an error saying that "call to super must be the first statement in the constructor".

问题是它我的构造函数中的第一个语句。

The problem is that it is the first statement in my constructor.

public void CheckingAccountCustomer(int a){
    super(n, p, b);
    accountNo = a;
}

这里也是我的超类。

public void customer(String n, int p, double b){
    name = n;
    pin = p;
    balance = b;
}

我在这里做错了什么?

推荐答案

此代码

public void customer(String n, int p, double b){

不是构造函数。构造函数没有返回类型,例如空隙。假设您的班级名称是 customer

is not a constructor. Constructors don't have return types, e.g. void. Assuming your class name is customer:

public customer(String n, int p, double b){

这适用于 CheckingAccountCustomer 也是。

这篇关于调用super必须是构造函数中的第一个语句,但它是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆