Study and learn Interview MCQ Questions and Answers on Java Recursion. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.
Go through Java Theory Notes on Recursion before reading these objective questions.
Yes. It is called recursion when you refer to the same method.
void methodA() { methodB(); } void methodB() { methodA(); }
No, not at all. In the above code, the first method calls the second method and the second method calls the first method.
Yes. Java uses Stack type memory to implement Recursion.
Recursion unwinds and completes all methods from the latest to the oldest. So, it requires the LIFO strategy offered by Stack memory.
Recursion works only with methods.
Loops or iterations are better memory-optimized than Recursion technique that solely depends on the Stack memory.
StackOverError occurs when the stack has been full and can not allocate space for continuing new method call.
True
Without a proper RETURN statement, the runtime calls the same method again and again for infinite times and causes memory issues.
Recursion makes a program small. So, the output class file will be less in size.
Yes. Recursion is a bit tricky. If wrongly programmed, the recursive method will be executed an infinite number of times causing Stack Overflow errors.
public class RecursionTesting { static int num=4; public static void main(String[] args) { new RecursionTesting().recursiveMethod(); } void recursiveMethod() { num--; if(num == 0) return; System.out.print(num + " "); recursiveMethod(); } }
Note that this recursive method does not return anything. It simply does the printing of some values.
TRUE.
public class RecursionTest2 { public static void main(String[] args) { RecursionTest2 rt2 = new RecursionTest2(); int sum = rt2.summer(4); System.out.println(sum); } int summer(int in) { int sum = 0; if(in ==0) return 0; sum = in + summer(--in); return sum; } }
10
IN 4 IN 3 IN 2 IN 1 IN 0 10
public class RecursionTest3 { public static void main(String[] args) { RecursionTest3 rt3 = new RecursionTest3(); int multiplication = rt3.multiplier(4); System.out.println(multiplication); } int multiplier(int in) { System.out.println("IN " + in); int mul = 0; if(in ==0) return 1; mul= in * multiplier(--in); return mul; } }
24
IN 4 IN 3 IN 2 IN 1 IN 0 24
A proper RETURN statement ends the recursion process when kept inside a conditional IF or ELSE block.
A VOID-Recursive method is useful only for printing or logging data in general.
There is no limit. The limit actually depends on the size of Stack Memory. If you process a large amount of data, it may lead to a Stack Overflow error.
Heap memory can store tens of thousands of objects. Stack memory is relatively small or limited.