KnowledgeBoat Logo
LoginJOIN NOW

Computer Applications

Explain the function of a return statement in Java programming.

User Defined Methods

ICSE 2006

41 Likes

Answer

A method returns a value through the return statement. Once a return statement is executed, the program control moves back to the caller method skipping the remaining statements of the current function if any. A method can have multiple return statements but only one of them will be executed. For example, consider the given method:


int sum(int a, int b) {
    int c = a + b;
    return c;
}

It uses a return statement to return a value of int type back to its caller.

Answered By

25 Likes


Related Questions