🎙 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 9 of 10

Why must local variables used inside a lambda be effectively final?

Why must local variables used inside a lambda be effectively final?

  1. A.Because lambdas cannot read variables
  2. B.Because final variables are faster
  3. C.The lambda gets a copy of the value and may run later, so the value must not change
  4. D.Because lambdas run on a separate thread every time
Answer & explanation

Correct answer: The lambda gets a copy of the value and may run later, so the value must not change

Java captures the value, not the variable; allowing changes would make the copy and the original disagree.

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 →