Given the code fragments:
Which code fragment, when inserted at line n1, enables the code to print Hank?
A.
B.
C.
D.
Given the code fragments:
Which code fragment, when inserted at line n1, enables the code to print Hank?
A.
B.
C.
D.
Why id D wrong?
I answered the same thing, and I was wrong, its missing the 𝙧𝙚𝙩𝙪𝙧𝙣 keyword.
C is the right one
C is the correct answer
public class Test { public static void checkAge(List<Person> personList, Predicate<Person> pearsonPredicate){ for(Person p : personList){ if(pearsonPredicate.test(p)){ System.out.println(p.name + " "); } } } public static void main(String[] args){ List<Person> personList = Arrays.asList(new Person("Hank", 45), new Person("Charlie", 40), new Person("Smith", 38) ); checkAge(personList, p -> p.getAge() > 40); } } Answer is C.
Answer is C. import java.util.Arrays; import java.util.List; import java.util.function.Predicate; public class TestPredicate { 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)); checkAge(iList, p -> p.getAge() > 40); } } Output: Hank