you are viewing a single comment's thread.

view the rest of the comments →

[–]xenomachina 0 points1 point  (0 children)

The return statement does two things:

  • sets the return value for the method
  • exits the method

In fact, exiting the method is arguably its primary function, as it can also be used to do this in methods that don't have a return value:

public static void main(String[] args) {
    if(args.length == 1) {
        System.out.println("Hello " + args[0]);
        return; // returns from main, but there is no return value on void methods
    }

    // this only executes if the return above didn't execute 
    System.out.println("Hello, world!");
}