Call to super must be first statement in the constructor, but it is

Phil Meyer picture Phil Meyer · May 6, 2013 · Viewed 23.7k times · Source

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;
}

And here is my superclass for this as well.

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

What am I doing wrong here?

Answer

rgettman picture rgettman · May 6, 2013

This code

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

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){

This applies to CheckingAccountCustomer too.