return statement returns from a method.
The return
statement immediately terminates the method in which it is executed.
public class Main {
public static void main(String args[]) {
boolean t = true;
System.out.println("Before return");
if (t)
return; // return to caller
System.out.println("after");
}
}
The output from this program is shown here:
Before return
Home
Java Book
Language Basics
Java Book
Language Basics
Statement:
- Simplest if statement
- If else statement
- switch statement
- while loop
- do-while statement
- for Loop
- for each loop
- break to Exit a Loop
- continue
- return statement returns from a method.
- Comments