Friday, 30 May 2014

Return Statement In Java

Return statement

The return statement is used to explicitly return from a method.That is it transfer the control to the caller of method.
And most important , return statement is always be the last statement of the current block.

Simple Program for Return statement:

package org.modi;
public class Test
{
    public static void main(String[] args)
    {
       System.out.println("Main method begin");
       if(true)
       {
          return; //it is last statement of current (if) block
       }
       System.out.println("Main method end");
    }
}
OUTPUT
Main method begin
From this program we can see that , when return statement encountered the execution of method terminated.







0 comments :

Post a Comment