Which code fragment, when inserted at line n1, enables the code to print Hank?

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; });

Download Printable PDF. VALID exam to help you PASS.

2 thoughts on “Which code fragment, when inserted at line n1, enables the code to print Hank?

  1. 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;
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.