53.6k views
2 votes
Analyze the following recursive method.

public static long factorial(int n) {
return n * factorial(n - 1);
}
A. Invoking factorial(0) returns 0.
B. Invoking factorial(1) returns 1.
C. Invoking factorial(2) returns 2.
D. Invoking factorial(3) returns 6.
E. The method runs infinitely and causes a StackOverflowError.

1 Answer

6 votes

Answer: E

Process is terminating due to StackOverflowException.

Step-by-step explanation:

System.StackOverflowException

HResult=0x800703E9

Message=Exception of type 'System.StackOverflowException' was thrown.

User Naota
by
6.0k points