Error invalid method declaration; return type required

1.3k Views Asked by At

I am receiving this type of error within jcreator but am unsure on how to fix. Here is the code line

public Account(String name, double balance)
{
    this.name = name;

    return name;

    if(balance>0.0)

    this.balance = balance;

    return balance;     

}
1

There are 1 best solutions below

0
On

Your method name would have to be changed to

public double Account(String name, double balance){
//code here
}

and if you are not creating an object or class file to go off of...aka if your calling the method standalone from the static main method like this:

public static void main(String[] args){

double a = Account(test1, 123);
}

you would need to make the method name with static, which would look like this:

public static double Account(String name, double balance){
//code here
}