🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Lambdas and Functional Interfaces: all 10 questions

Quiz: Lambdas and Functional Interfaces · Question 4 of 10

What does this print? (code)

What does this print?

import java.util.function.*;
public class Main {
    public static void main(String[] args) {
        Predicate<String> longWord = s -> s.length() > 4;
        Predicate<String> startsJ = s -> s.startsWith("J");
        System.out.println(longWord.or(startsJ).test("Java") + " " + longWord.and(startsJ).test("Java"));
    }
}
  1. A.true true
  2. B.false false
  3. C.true false
  4. D.false true
Answer & explanation

Correct answer: true false

"Java" has length 4 (not more than 4) but starts with J: or gives true, and gives false.

Can you get the rest right without peeking?

Take the timed Quiz: Lambdas and Functional Interfaces quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →