Oracle
1Z0-809 · Question #64
1Z0-809 Question #64: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-809 to reveal the answer and full explanation for question #64. The question stem and answer options stay visible for context.
Question
Given the following code and code fragment:
class Sum extends RecursiveAction { //line n1
static final int THRESHOLD_SIZE = 3;
int stIndex, lsIndex;
int [] data;
public Sum(int []data, int start, int end) {
this.data = data;
this.stIndex = start;
this.lsIndex = end;
}
protected void compute () {
int sum = 0;
if (lsIndex ? stIndex<= THRESHOLD_SIZE) {
for (int i = stIndex; i < lsIndex; i++) {
sum = data [i];
}
System.out.println(sum);
} else {
new Sum (data, stIndex + THRESHOLD_SIZE, lsIndex).fork();
new Sum (data, stIndex,
Math.min (stIndex, stIndex + THRESHOLD_SIZE)
).compute ();
}
}
}
And the code fragment:
ForkJoinPool fjpool = new ForkJoinPool ();
int data [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
fjpool.invoke (new Sum (data, 0, data.length));
And given that the sum of all integers from 1 to 10 is 55.
Which statement is true?Options
- AThe program prints several values that total 55.
- BThe program prints 55.
- CA compilation error occurs at line n1.
- DThe program prints several values whose sum exceeds 55.
Unlock 1Z0-809 to see the answer
You've previewed enough free 1Z0-809 questions. Unlock 1Z0-809 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.