Answer the question
In order to leave comments, you need to log in
How does recursion work in Java?
Hello everyone, who can tell what happens to the function with this code?
public void save(){
String myString =n.readstring();
if(n==null){
save();
return;
}
this.classString = myString;
}
Answer the question
In order to leave comments, you need to log in
When you call a method from within another method, the calling method is suspended in a partially completed state. All values of the variables of the calling function are physically stored in memory. The method called by the method that calls it is placed on top of the calling method, and the same thing happens as long as the recursive case is met (the condition under which the method calls itself). When the base case (the condition under which the recursion must be stopped) occurs, the methods return control to the method that called them in turn, until the original (bottom-most) method completes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question