What is the purpose of Return Statement ?

Discussion in 'Flow Control' started by vbraojava, Sep 17, 2008.

  1. vbraojava

    vbraojava New Member

    The last of the Branching Statements is the return statement. The return statement exits from the current method, and control flow returns to where the method was invoked.

    The return statement has two forms :

    1. Returns a value
    2. Doesn't returns a value

    Returns a value : To return a value, simply put the value (or an expression that calculates the value) after the return keyword. The data type of the returned value must match the type of the method's declared return value.

    return ++count;

    Doesn't returns a value : When a method is declared void, use the form of return that doesn't return a value.

    return;
     

  2. jagsjava

    jagsjava New Member

    IN order to return a value we have to use the return statement in the method.
    The return statement is compulsory for the methods with Datatype.
    Eg: int Java(int x,int y)
    {f
    int c=x+y;
    return c;
    }
    In the above Eg: the method Java is with a int datatype.so it must contain a return statement. i.e it returns a integer value.

    Only method with void keyword doest not contains a return statement. i.e the method does not returns any value.
    Eg: void Java()
    {
    System.out.println("This is java");
    }
     
  3. williams22

    williams22 New Member

    Thank you so much... you had even helped me too
     
  4. sachin0990

    sachin0990 New Member

    Very useful information. Thank you for sharing it.
     

Share This Page