Bird
0
0

Which of the following is the correct way to call the function fun greet(name: String, age: Int) using named arguments?

easy📝 Syntax Q12 of 15
Kotlin - Functions
Which of the following is the correct way to call the function fun greet(name: String, age: Int) using named arguments?
Agreet(age = 25, "Anna")
Bgreet(name = "Anna", 25)
Cgreet(name = "Anna", age = 25)
Dgreet(name: "Anna", age: 25)
Step-by-Step Solution
Solution:
  1. Step 1: Check named argument syntax

    Named arguments use parameter = value syntax, so greet(name = "Anna", age = 25) is correct.
  2. Step 2: Identify incorrect options

    greet(name = "Anna", 25) mixes positional and named incorrectly; C has wrong order without naming first argument; D uses colon instead of equals.
  3. Final Answer:

    greet(name = "Anna", age = 25) -> Option C
  4. Quick Check:

    Named argument syntax uses = not : = A [OK]
Quick Trick: Use parameter = value format for named arguments [OK]
Common Mistakes:
MISTAKES
  • Using colon (:) instead of equals (=) in named arguments
  • Mixing positional and named arguments incorrectly
  • Passing arguments in wrong order without naming

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes