Oracle
1Z0-809 · Question #186
1Z0-809 Question #186: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-809 to reveal the answer and full explanation for question #186. The question stem and answer options stay visible for context.
Question
Given:
public class Product {
String name;
int qty;
public String toString() {
return name;
}
public Product(String name, int qty) {
this.name = name;
this.qty = qty;
}
static class ProductFilter {
public boolean isAvailable(Product p) { // line n1
return p.qty >= 10;
}
}
}
and the code fragment:
List<Product> products = Arrays.asList(
new Product("MotherBoard", 5),
new Product("Speaker", 20));
products.stream()
.filter(product.ProductFilter::isAvailable) // line n2
.forEach(p -> System.out.println(p));
Which modification enables the code fragment to print Speaker?
Options
- AImplement Predicate in the Product.ProductFilter class and replace line n2 with .filter (p -> p.ProductFilter.test (p))
- BReplace line n1 with: public static boolean isAvailable (Product p) { return p.qty >= 10; } Replace line n2 with: .filter (p -> p.ProductFilter.isAvailable (p))
- CReplace line n2 with: .filter (p -> Product::isAvailable)
- DReplace line n2 with: .filter (p -> Product::ProductFilter::isAvailable ())
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.