nerdexam
Oracle

1Z0-808 · Question #45

1Z0-808 Question #45: Real Exam Question with Answer & Explanation

Sign in or unlock 1Z0-808 to reveal the answer and full explanation for question #45. The question stem and answer options stay visible for context.

Working with Methods and Encapsulation

Question

Person.java: public class Person { String name; int age; public Person(String n, int a) { name = n; age = a; } public String getName() { return name; } public int getAge() { return age; } } Test.java: public static void checkAge(List<Person> list, Predicate<Person> predicate) { for (Person p : list) { if (predicate.test(p)) { System.out.println(p.name + " "); } } } public static void main(String[] args) { List<Person> iList = Arrays.asList(new Person("Hank", 45), new Person("Charlie", 40), new Person("Smith", 38)); //line n1 } Which code fragment, when inserted at line n1, enables the code to print Hank?

Options

  • AcheckAge (iList, () -> p. get Age () > 40);
  • BcheckAge (iList, Person p -> p.getAge() > 40);
  • CcheckAge (iList, p-> p.getAge() > 40);
  • DcheckAge (iList, (Person p) -> {p.getAge() > 40;});

Unlock 1Z0-808 to see the answer

You've previewed enough free 1Z0-808 questions. Unlock 1Z0-808 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.

Topics

#Lambda expressions#Predicate interface#Functional interfaces#Type inference
Full 1Z0-808 Practice