DEV Community

velvizhi Muthu
velvizhi Muthu

Posted on

Module 4: Return and void keyword

What is the "return" keyword?
The return keyword in Java is used inside a method to:

Exit from the method immediately.

Used just to exit the method (no value returned).

Optionally send back a value to the caller (if the method has a return type other than void).

The type of the value returned must match the method’s declared return type.

If the method is declared as void, you can use plain return or omit it.

return immediately ends method execution; any code after it won’t run.

You can use return inside loops, conditionals, or directly in methods.

What are "Void" keywords?
The keyword void is a return type used for methods that do not return any value.

Note: Primitive data type is a Java keyword because the first letter is lowercase.

Non primitive data type is a Java.lang
The non primitive data type -first letter is an uppercase.

Top comments (0)