Kotlin - FunctionsWhich of the following Kotlin function declarations will cause a syntax error?Afun add(x: Int, y: Int = 5) = x + yBfun printMessage(message = "Hi") { println(message) }Cfun multiply(x: Int = 2, y: Int) = x * yDfun greet(name: String = "User") { println("Hello, $name") }Check Answer
Step-by-Step SolutionSolution:Step 1: Understand parameter order rulesParameters with default values must come after parameters without defaults.Step 2: Analyze fun multiply(x: Int = 2, y: Int) = x * yfun multiply(x: Int = 2, y: Int) = x * y has a default parameter before a non-default one, causing syntax error.Final Answer:fun multiply(x: Int = 2, y: Int) = x * y -> Option CQuick Check:Default params must follow non-defaults [OK]Quick Trick: Put default parameters after non-default ones [OK]Common Mistakes:MISTAKESPlacing default parameters before required onesIgnoring Kotlin parameter order rules
Master "Functions" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - List creation (listOf, mutableListOf) - Quiz 5medium Collections Fundamentals - Array creation and usage - Quiz 13medium Collections Fundamentals - Array creation and usage - Quiz 11easy Control Flow as Expressions - Why expressions over statements matters - Quiz 8hard Control Flow as Expressions - Smart casts in when and if - Quiz 13medium Data Types - Boolean type and logical operators - Quiz 14medium Kotlin Basics and JVM Runtime - Comments and documentation syntax - Quiz 8hard Loops and Ranges - For loop with step and downTo - Quiz 13medium Loops and Ranges - Labeled break and continue - Quiz 12easy Variables and Type System - Constant values with const val - Quiz 9hard