The question is:
What is the result of executing the following application? (Choose all that apply.)
Answer options:
A. It compiles and runs without issue.
B. The code will not compile because of m1.
C. The code will not compile because of m2.
D. The code will not compile because of m3.
E. It compiles but throws an exception at runtime.
F. It compiles but hangs at runtime.
The correct answer is:
E. The program compiles without issue, so B, C, and D are incorrect. Lines m2 and m3
throw a compiler warning about generics but still compile. Notice that RecursiveAction,
unlike RecursiveTask, does not return a value. However, since we used a generic Fork-
JoinTask reference, the code still compiles. The issue here is that the base condition is not
reached since the numbers start/end are consistently positive. This causes an infinite loop,
although since memory is finite,
Java detects this and throws a StackOverflowError, so E
is correct. In practice, this could also generate a locking exception before the StackOverflowError
when the program runs out of memory, but in either circumstance, the program
will exit.
If correct answer is E it should be either "It compiles but throws an
error at runtime." or "It compiles but throws an
throwable at runtime.". Because of the
exception word I switch my answer to option F despite the fact the book is mentioned that we should take into account that it will be infinite recursion that will end up as StackOverflowError or OutOfMemoryError