Return in void method | SoloLearn: Learn to code for FREE!

+2

Return in void method

Is there void method that has return keyword? Because I saw one of them in a code related to the nodes of LinkedList. I want to know what's returned in this void method? It is sample: public void insertAfter(Node prev_node, int new_data) {     if (prev_node == null)     {         System.out.println("The given previous node cannot be null");         return;     } //It's part of a code!

8/13/2019 6:35:23 PM

Amir01

3 Answers

New Answer

+4

return is a reserved keyword to exit/end a method, with or without a value

+4

No value is returned. Only the program control flow is returned to the point of (just after) the method invocation.

+1

If the method returns void then return; just exits out of the method at that statement.