Given the code fragments:
Which code fragment, when inserted at line n1, enables the code to print Hank?
A. checkAge (iList, ( ) -> p. get Age ( ) > 40);
B. checkAge(iList, Person p -> p.getAge( ) > 40);
C. checkAge (iList, p -> p.getAge ( ) > 40);
D. checkAge(iList, (Person p) -> { p.getAge() > 40; });
C
public static void checkAge(List list, Predicate predicate) {
for (Person p :list){
if(predicate.test(p) ){
System.out.println(p.name+” “);
}
}
}
public static void main(String[] args) {
List iList= Arrays.asList(new Person(45,”Hank”),new Person(40,”Charlie”),new Person(38,”Smith”));
checkAge(iList,p->(p.getAge()>40));
}
}
class Person{
int age;
String name;
Person(int a,String n){
name=n;
age=a;
}
public int getAge() {
return age;
}
public String getName() {
return name;
}
}
Answer C:
Mainly because other options have syntax errors.