Java Keyword Return

The reserved keyword return is used to finish the execution of a Java method. You declare a method return type in the declaration of the method. Within the body of the method, you use the return statement to return a value. A method declared void should not return a value.

A void method can call return without a value just to exit the method and return control back to calling code.

//JavaCodeDepot Sample 

public void jcdMethodA() {

    return;
}


A method that is not void must have a return statement with a corresponding data type from the method signature. The sample method below is defined to return an int so our return statement must use the same data type.

//JavaCodeDepot Sample 

public int jcdMethodA() {

    int retValue = 7;
    
    return retValue;
}


The complete list of Java reserved keywords contains a total of 50 keywords and 3 literal words that are unable to be used as variable names.

Add a Comment

Your email address will not be published. Required fields are marked *