Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
22.7. Scope and Access
This section
Practice test
10 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
2 cards from this lesson. Good the night before a test.
Try these first
- 1.
What does it mean for a variable to be effectively final?
Hint
Think about how the variable is used in a lambda.
- 2.
Can you use a variable that is modified after its declaration inside a lambda?
Hint
Consider the definition of effectively final.
- 3.
What is an effectively final variable?
- A variable that can change after declaration
- A variable never modified after assignment
- Any declared variable
Hint
Reflect on the term 'effectively'.
- 4.
Can a lambda modify local variables in its enclosing scope?
- True
- False
Hint
Think about the rules that restrict what lambdas can access.
- 5.
Create a Java program that uses a lambda to sum the values of an array while trying to modify a local counter inside the lambda. What errors arise?
Hint
Check what happens to any counter variable if you try to redefine it in the lambda.
- 6.
Illustrate with code how an effectively final variable can be used in a sorting lambda while clarifying why a non-final variable cannot be used.
Hint
Experiment with creating two different versions of the same functionality.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
4 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
Get your answers marked and your progress tracked
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting