Oracle
1Z0-809 · Question #38
1Z0-809 Question #38: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-809 to reveal the answer and full explanation for question #38. The question stem and answer options stay visible for context.
Question
Given:
public class product {
int id; int price;
public Product (int id, int price) {
this.id = id;
this.price = price;
}
public String toString() { return id + ":" + price; }
}
and the code fragment:
List products = new ArrayList (Arrays.asList(new Product(1, 10),
new Product (2, 30),
new Product (2, 30)));
Product p = products.stream().reduce(new Product (4, 0), (p1, p2) ->
{p1.price+=p2.price;
p1.id=p1.id+p2.id;
return p1;
});
products.add(p);
products.stream().parallel()
.reduce((p1, p2) -> p1.price > p2.price ? p1 : p2)
.ifPresent(System.out::println);
What is the result?
Options
- A2:30
- B4:0
- C4:60
- D6:60
- EThe program prints nothing.
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.