1Z0-829 · Question #26
Given: public class Test { public String attach1(List<String> data) { return data.parallelStream().reduce("w", (n,m) -> n+m, String::concat); } public String attach2(List<String> data) { return…
The correct answer is E. Compilation fails. Compilation fails because the code uses List<String> as a parameter type and calls List.of(...), but java.util.List is never imported - any class outside java.lang must be explicitly imported, so the compiler rejects the file before any execution occurs. Since the program never…
Question
Options
- ATablechair Tablechair
- BWTablechair Tablechair
- CA NullPointerException is thrown
- DWTablechair TableChair
- ECompilation fails
How the community answered
(47 responses)- A21% (10)
- B6% (3)
- C2% (1)
- D9% (4)
- E62% (29)
Explanation
Compilation fails because the code uses List<String> as a parameter type and calls List.of(...), but java.util.List is never imported - any class outside java.lang must be explicitly imported, so the compiler rejects the file before any execution occurs. Since the program never compiles, options A, B, and D (which describe specific runtime string outputs) are impossible, and option C (NullPointerException) is equally impossible for the same reason. Even if you added the missing import, option C would still be wrong because reduce((p,l) -> p+l) on a non-empty list returns a populated Optional<String>, so .get() would not throw; and options A/B/D are wrong because the 3-argument parallel reduce in attach1 applies the identity "w" to each partition independently, so the output would be something like "wTablewChair" - not matching any listed value.
Memory tip: On OCP questions, always scan for types outside java.lang (List, Optional, Map, etc.) before analyzing runtime behavior - if even one is used without an import, the answer is "compilation fails" regardless of how correct the logic looks.
Topics
Community Discussion
No community discussion yet for this question.