The question is:
What is the result of executing the following application? (Choose all that apply.)
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
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 exceptionword 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
Jeanne Boyarsky wrote:. . . In practice, people say 'exception" meaning "anything that could be thrown at runtime." . . .
So does the JLS (=Java® Language Specification). It uses the term “exception classes” for Throwable and all its subtypes, and it has similarly precise meanings for “checked exceptions” and “unchecked exceptions”. So that particular convention has official backing.
Good heavens! What have you done! Here, try to fix it with this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java