Bird
0
0

Which of the following is the correct syntax to declare a local function inside a Kotlin function?

easy📝 Syntax Q12 of 15
Kotlin - Functions
Which of the following is the correct syntax to declare a local function inside a Kotlin function?
Afun outer() { fun inner() { println("Hi") } }
Bfun outer() { def inner() { println("Hi") } }
Cfun outer() { function inner() { println("Hi") } }
Dfun outer() { inner() fun { println("Hi") } }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kotlin function syntax

    Kotlin uses the keyword 'fun' to declare functions, including local ones.
  2. Step 2: Check each option

    fun outer() { fun inner() { println("Hi") } } uses 'fun' correctly for both outer and inner functions. Others use invalid keywords or wrong order.
  3. Final Answer:

    fun outer() { fun inner() { println("Hi") } } -> Option A
  4. Quick Check:

    Local function syntax uses 'fun' keyword [OK]
Quick Trick: Local functions use 'fun' keyword inside another function [OK]
Common Mistakes:
MISTAKES
  • Using 'def' or 'function' instead of 'fun'
  • Placing 'fun' after the function call
  • Missing braces for function body

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes