exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 25 discussion

Actual exam question from Oracle's 1z0-809
Question #: 25
Topic #: 1
[All 1z0-809 Questions]

Given the code fragments:
interface CourseFilter extends Predicate<String> {
public default boolean test (String str) {
return str.equals ("Java");
}
}
and
List<String> strs = Arrays.asList("Java", "Java EE", "Java ME");
Predicate<String> cf1 = s - > s.length() > 3;
Predicate cf2 = new CourseFilter() { //line n1
public boolean test (String s) {
return s.contains ("Java");
}
};
long c = strs.stream()
.filter(cf1)
.filter(cf2 //line n2
.count();
System.out.println(c);
What is the result?

  • A. 2
  • B. 3
  • C. A compilation error occurs at line n1.
  • D. A compilation error occurs at line n2.
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Ritesh_
Highly Voted 4 years, 9 months ago
It will print 3
upvoted 9 times
...
adnano1234
Highly Voted 4 years, 6 months ago
The answer is : 3
upvoted 5 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 4 weeks ago
B is the correct answer. import java.util.Arrays; import java.util.List; import java.util.function.Predicate; interface CourseFilter extends Predicate<String> { public default boolean test(String str) { return str.equals("Java"); } } public class Main { public static void main(String[] args) { List<String> strs = Arrays.asList("Java", "Java EE", "Java ME"); Predicate<String> cf1 = s -> s.length() > 3; Predicate cf2 = new CourseFilter() { // line n1 public boolean test(String s) { return s.contains("Java"); } }; long c = strs.stream() .filter(cf1) .filter(cf2) // line n2 .count(); System.out.println(c); } }
upvoted 1 times
asdfjhfgjuaDCV
4 months, 4 weeks ago
I think there is one typo in in //line2
upvoted 1 times
...
...
steefaand
5 months, 4 weeks ago
Selected Answer: B
After fixing typos answer is B.
upvoted 1 times
...
r1muka5
1 year, 5 months ago
Compilation error occurs at line n2 as it's obviously missing parenthesis ')' so the actual answer is D. If it had compiled then the outpub would be 3 and the answer - C.
upvoted 2 times
GaelBernard
11 months, 3 weeks ago
I believe it's just a typo. ExamTopics has several mistakes of this type for the OCP exam.
upvoted 1 times
...
DangNHH
1 year, 4 months ago
I agree with you
upvoted 1 times
...
...
Mudzingwa
1 year, 10 months ago
C what about C can we create an instance of an Interface
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Answer is 3.........
upvoted 1 times
...
Innovation
4 years, 6 months ago
output 3 is correct, tested
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago