. Advertisement .
..3..
. Advertisement .
..4..
I am working on java, but I found the following warning message:
.\Voter.java:14: error: invalid method declaration; return type
required
.\Candidates.java:7: error: invalid method declaration; return type
required
.\Candidates.java:14: error: invalid method declaration; return type
required
Is there any way to stabilize the issue “invalid method declaration; return type required”? I read a lot of topics about this, but all of them were trying to install anything. Is this the correct way, or any recommendation for me? Please find the beginning command below:
package org.arpit.java2blog;
public class Employee {
String name;
int age;
public Employee(String name) {
this.name = name;
}
public setEmployeeDetails(String name,int age)
{
this.name=name;
this.age=age;
}
}
The cause: The error happens because you get compilation at line 13 with error invalid method declaration; return type required.
Solution:
Let’s change this line:
to
Your method
setDetails
has not specified any return type. If it isn’t returning anything, then please specifyvoid
Voter
classCandidates
classAnother thing, (Thanks Frank Pavageau). Your class name is
Candidates
. You have defined the constructor usingCandidate
but nots
. This is why it should have a return type. Your constructor can be renamedCandidates
orCandidate
.