Bird
0
0

Given the function fun showInfo(name: String, age: Int), which of the following calls correctly uses named arguments?

easy📝 Conceptual Q2 of 15
Kotlin - Functions
Given the function fun showInfo(name: String, age: Int), which of the following calls correctly uses named arguments?
AshowInfo(25, name = "Alice")
BshowInfo("Alice", age = 25)
CshowInfo(name = "Alice", 25)
DshowInfo(age = 25, name = "Alice")
Step-by-Step Solution
Solution:
  1. Step 1: Review named argument syntax

    Named arguments require specifying the parameter name followed by an equals sign and the value.
  2. Step 2: Check each option

    showInfo(age = 25, name = "Alice") correctly names both parameters. Options B, C, and D mix positional and named arguments incorrectly.
  3. Final Answer:

    showInfo(age = 25, name = "Alice") -> Option D
  4. Quick Check:

    Named arguments must be in the form param = value. [OK]
Quick Trick: Named arguments require param = value syntax [OK]
Common Mistakes:
MISTAKES
  • Mixing positional arguments after named arguments incorrectly
  • Omitting parameter names when using named arguments
  • Using named arguments without equals sign

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes