Bird
0
0

Which of the following is true about vararg parameters in Kotlin?

easy📝 Conceptual Q2 of 15
Kotlin - Functions

Which of the following is true about vararg parameters in Kotlin?

AYou can have multiple <code>vararg</code> parameters in one function
B<code>vararg</code> parameters must be the last parameter in the function
C<code>vararg</code> parameters can only be of type String
D<code>vararg</code> parameters cannot be used with default values
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kotlin vararg rules

    Only one vararg parameter is allowed per function, and it can be anywhere if named parameters are used, but usually last for simplicity. Also, vararg parameters cannot have default values.
  2. Step 2: Evaluate each option

    vararg parameters cannot be used with default values - correct. vararg parameters must be the last parameter - false (named arguments allow otherwise). vararg parameters can only be of type String - false. Multiple vararg parameters in one function - false.
  3. Final Answer:

    Vararg parameters cannot be used with default values -> Option D
  4. Quick Check:

    Vararg default value = not allowed [OK]
Quick Trick: Vararg cannot have default values in Kotlin functions [OK]
Common Mistakes:
MISTAKES
  • Assuming multiple varargs allowed
  • Thinking vararg must be last always
  • Believing vararg only works with strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes