Home Segments Top Top Previous Next

112: Mainline

For example, in the following variation on the program in Segment 106, display is handled in the displayMovieRating method, so there is no value to be returned. Accordingly, void appears instead of a data-type name in the definition of displayMovieRating, and displayMovieRating contains no return statement—that is, no statement containing the return keyword:

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);                                 
 }                                                                
} 
--- Result --- 
The rating of the movie is 23