Bird
0
0

Which statement about local functions in Kotlin is TRUE?

easy📝 Conceptual Q2 of 15
Kotlin - Functions
Which statement about local functions in Kotlin is TRUE?
ALocal functions must be declared outside any other function.
BLocal functions can access variables from the outer function.
CLocal functions cannot return values.
DLocal functions are visible to other classes.
Step-by-Step Solution
Solution:
  1. Step 1: Recall local function scope

    Local functions are nested inside other functions and can access variables from their outer function.
  2. Step 2: Evaluate each option

    Local functions are declared inside functions. Local functions can return values. Local functions are not visible outside their containing function.
  3. Final Answer:

    Local functions can access variables from the outer function. -> Option B
  4. Quick Check:

    Local functions access outer variables = True [OK]
Quick Trick: Local functions see outer variables like a nested box [OK]
Common Mistakes:
MISTAKES
  • Thinking local functions are top-level
  • Believing local functions cannot return anything
  • Assuming local functions are accessible outside their function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes