Bird
0
0

Why does Kotlin require parameters with default values to be declared after parameters without default values?

hard📝 Conceptual Q10 of 15
Kotlin - Functions
Why does Kotlin require parameters with default values to be declared after parameters without default values?
ATo avoid ambiguity in function calls and maintain clear argument matching
BBecause Kotlin does not support default values for the first parameter
CTo force all parameters to have default values
DTo improve runtime performance by ordering parameters
Step-by-Step Solution
Solution:
  1. Step 1: Understand parameter matching

    Kotlin matches arguments to parameters by position unless named arguments are used.
  2. Step 2: Reason about ambiguity

    If default parameters came first, it would be unclear which arguments match which parameters.
  3. Final Answer:

    To avoid ambiguity in function calls and maintain clear argument matching -> Option A
  4. Quick Check:

    Parameter order avoids call ambiguity [OK]
Quick Trick: Default params after required to keep calls clear [OK]
Common Mistakes:
MISTAKES
  • Thinking it's a performance rule
  • Believing Kotlin disallows defaults first

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes