Kotlin - FunctionsWhich 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") } }Check Answer
Step-by-Step SolutionSolution:Step 1: Recall Kotlin function syntaxKotlin uses the keyword 'fun' to declare functions, including local ones.Step 2: Check each optionfun outer() { fun inner() { println("Hi") } } uses 'fun' correctly for both outer and inner functions. Others use invalid keywords or wrong order.Final Answer:fun outer() { fun inner() { println("Hi") } } -> Option AQuick Check:Local function syntax uses 'fun' keyword [OK]Quick Trick: Local functions use 'fun' keyword inside another function [OK]Common Mistakes:MISTAKESUsing 'def' or 'function' instead of 'fun'Placing 'fun' after the function callMissing braces for function body
Master "Functions" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Array creation and usage - Quiz 8hard Control Flow as Expressions - When with ranges and types - Quiz 2easy Control Flow as Expressions - Smart casts in when and if - Quiz 12easy Data Types - Any type as universal base - Quiz 9hard Functions - Parameters with default values - Quiz 3easy Functions - Function declaration syntax - Quiz 13medium Loops and Ranges - For loop with ranges - Quiz 3easy Operators and Expressions - Range operator (..) and in operator - Quiz 9hard Variables and Type System - String templates and interpolation - Quiz 14medium Variables and Type System - Val for immutable references - Quiz 8hard