+ 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!
3 Answers
+ 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.