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


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


3 Answers

New Answer


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


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


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