Java return from a method in the middle without condition

Question

What is the output of the following code?

// Demonstrate return.
public class Main {
  public static void main(String args[]) {
    boolean t = true;

    System.out.println("Before the return.");


    return; // return to caller
  

    System.out.println("This won't execute.");
  }/*from   w  ww.  ja  va 2 s  . c om*/
}


Compile time error:
Unreachable code



PreviousNext

Related