Bird
0
0

What is wrong with the following Kotlin function call?

medium📝 Debug Q6 of 15
Kotlin - Functions
What is wrong with the following Kotlin function call?
fun multiply(x: Int, y: Int) = x * y

multiply(x = 4, 5)
APositional argument cannot follow named argument.
BParameter names must be omitted when using named arguments.
CFunction multiply does not accept named arguments.
DThe function call is correct and will compile.
Step-by-Step Solution
Solution:
  1. Step 1: Understand argument order rules

    In Kotlin, once you use a named argument, all subsequent arguments must also be named.
  2. Step 2: Analyze the call

    The call uses a named argument for x but then a positional argument 5 for y, which is invalid.
  3. Final Answer:

    Positional argument cannot follow named argument. -> Option A
  4. Quick Check:

    Named arguments must come after positional or all must be named. [OK]
Quick Trick: No positional args after named args [OK]
Common Mistakes:
MISTAKES
  • Placing positional arguments after named arguments
  • Assuming named arguments can be mixed arbitrarily
  • Ignoring Kotlin's argument order rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes