Reputation: 3
this is the question on the homework: "If the person works, in hours per week, less than or equal to the number of hours in a normal work week, then the income is simply the payrate times hoursWorkedPerWeek."
this is the code i have, it says it's an unreachable statement:
public double getGrossIncome() {
double income = 0;
return income;
if(hoursWorkedPerWeek <= NORMAL_WORK_WEEK){
income = payRate * hoursWorkedPerWeek;
}
}
Upvotes: 0
Views: 37
Reputation: 385
The statements which are written after the return statement are never executed. Hence all these statements are termed unreachable statements. We can have multiple return statements inside a method based on certain conditions.
For eg: In this method we have 2 return statements based on certain criteria.
public String process(int x){
if (x<18){
return "Not eligible";
//Not reachable area
}
else{
return "eligible";
//Not reachable area
}
}
Upvotes: 1