Because displayMovieRating
has no return statement, it is said to
fall off its end, returning nothing; that behavior is allowed for
only those methods that have a void
return type.
Picky programmers think that defining a method that can fall off its end is
inelegant. Those programmers write empty return
statements, as in the
following slightly amended version of displayMovieRating
:
public class Demonstrate {
public static void main (String argv[]) {
int script = 6, acting = 9, direction = 8;
displayMovieRating(script, acting, direction);
}
public static void displayMovieRating (int s, int a, int d) {
System.out.print("The rating of the movie is ");
System.out.println(s + a + d);
return;
}
}