Return Statement In Java example
Chapter:
Control Statements
Last Updated:
15-07-2016 10:20:18 UTC
Program:
/* ............... START ............... */
public class JavaReturnExample {
public static void main(String args[]) {
boolean t = true;
System.out.println("Before return.");
if (t)
return; // return to caller
System.out.println("This statement will not execute.");
}
}
/* ............... END ............... */
Output
Notes:
-
The return statement is used to explicitly return from a method. That is, it causes program control to transfer back to the caller of the method.
- Every method returns.
- A method that returns no value is void.
Tags
Return Statement, Java