1Z0-809 · Question #221
Given the definition of the Emp class: public class Emp { private String eName; private Integer eAge; Emp(String eN, Integer eA) { this.eName = eN; this.eAge = eA; } public Integer getEAge() {return…
The correct answer is A. Sam John Jim. Option A is correct (note: "Jim" in the answer appears to be a typo for "Jill") because the predicate s.getEAge() <= 60 evaluates to true for all three employees - Sam (20), John (60), and Jill (51) - so none are filtered out, and all three names are printed in insertion order…
Question
Options
- ASam John Jim
- BJohn Jim
- CA compilation error occurs at line n1.
- DA compilation error occurs at line n2.
How the community answered
(36 responses)- A83% (30)
- B6% (2)
- C8% (3)
- D3% (1)
Explanation
Option A is correct (note: "Jim" in the answer appears to be a typo for "Jill") because the predicate s.getEAge() <= 60 evaluates to true for all three employees - Sam (20), John (60), and Jill (51) - so none are filtered out, and all three names are printed in insertion order.
Option B is wrong because it excludes Sam, which would only make sense if the predicate were < 60 or > some_threshold; since 20 ≤ 60 is true, Sam passes the filter and appears in the output.
Option C is wrong because the lambda s -> s.getEAge() <= 60 is perfectly valid for Predicate<Emp> - it takes an Emp argument and returns a boolean, satisfying the functional interface contract.
Option D is wrong because Emp::getEName is a valid method reference that maps Emp → String, making it a legal argument to stream().map() which produces a Stream<String>.
Memory tip: When evaluating filter predicates on exams, quickly substitute each element's value and check the condition - don't assume the predicate eliminates anything without testing the boundary values (here 60 <= 60 is true, which catches test-takers who think of <= as <).
Community Discussion
No community discussion yet for this question.