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.

  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)
    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.
  5. anneroberts

    anneroberts Member

    Those exchange articulation terminates those execution of a work Also returns control of the calling capacity. Execution resumes in the calling work toward the side of the point promptly accompanying the call. An exchange articulation camwood Additionally profit a worth of the calling capacity. See profit sort for additional data.

Share This Page