A return statement does things: it sends a value back to the caller and it immediately exits the method. No code after a return in the same block will execute.
public static String grade(int score) {
if (score >= 90) {
return "A";
}
if (score >= 80) {
return "B";
}
return "C";
}
If score is , the first return fires and the method exits. Java never checks the second if. This is how return controls the flow inside a method.
The compiler requires that every possible path through your method reaches a return statement (for non-void methods). If you put the last return inside an else block and forget the case where no if matches, the compiler will flag the missing return.