Test Series - java

Test Number 54/64

Q: Recursion in Java is a way of calling the method from within the same method. State TRUE or FALSE.
A. TRUE
B. FALSE
C. -
D. -
Solution: Yes. It is called recursion when you refer to the same method.
Q: Check the below code and state whether it is called Recursion in Java?
void methodA()
{
  methodB();
}
void methodB()
{
  methodA();
}
A. TRUE
B. FALSE
C. -
D. -
Solution: No, not at all. In the above code, the first method calls the second method and the second method calls the first method.
Q: Java uses ___ type of memory to implement Recursion.
A. Heap
B. Stack
C. Register
D. None
Solution: Yes. Java uses Stack type memory to implement Recursion.
Q: Java uses Stack type memory instead of Heap type memory in implementing Recursion because of ___ feature of STACK.
A. FIFO (First In First Out)
B. LIFO (Last In First Out)
C. Round Robin
D. None
Solution: Recursion unwinds and completes all methods from the latest to the oldest. So, it requires the LIFO strategy offered by Stack memory.
Q: Recursion in Java applies to ___.
A. Constructors
B. Variables
C. Methods
D. Blocks
Solution: Recursion works only with methods.
Q: Uses are Recursion in Java are___.
A. Traversing folders and files on a disk
B. Traversing the nodes of a Binary Tree
C. Evaluating Nth order equations and Factorials
D. All the above
Solution: -
Q: Which is better in terms of memory utilization Recursion or Loops in Java?
A. Recursion
B. Loops
C. -
D. -
Solution: Loops or iterations are better memory-optimized than Recursion technique that solely depends on the Stack memory.
Q: Which is the common problem with Recursive methods in Java?
A. StackOverflowError
B. IndexOutOfBoundsException
C. OutOfMemoryError
D. None
Solution: StackOverError occurs when the stack has been full and can not allocate space for continuing new method call.
Q: Recursion usually stops when the Java Runtime encounters an IF or ELSE statement with a RETURN statement. State TRUE or FALSE.
A. FALSE
B. TRUE
C. -
D. -
Solution: True
Q: Attempting to call a method recursively without a proper RETURN statement leads to ___.
A. Stack Overflow errors
B. Buffer Overflow errors
C. Compile-time errors
D. ALL
Solution: Without a proper RETURN statement, the runtime calls the same method again and again for infinite times and causes memory issues.

You Have Score    /10