Bird
0
0

Consider the function:

hard📝 Application Q8 of 15
Kotlin - Functions
Consider the function:
fun reserveSeat(name: String, eventDate: String, seatType: String = "Regular") {
    println("Reservation for $name on $eventDate, Seat: $seatType")
}

Which call correctly uses named arguments to reserve a seat for "Emma" on "2024-12-15" with the default seat type?
AreserveSeat(name = "Emma", eventDate = "2024-12-15")
BreserveSeat("Emma", seatType = "Regular", "2024-12-15")
CreserveSeat(eventDate = "2024-12-15", "Emma")
DreserveSeat(seatType = "Regular", name = "Emma", eventDate = "2024-12-15")
Step-by-Step Solution
Solution:
  1. Step 1: Understand default parameters

    The parameter seatType has a default value, so it can be omitted.
  2. Step 2: Check named argument usage

    reserveSeat(name = "Emma", eventDate = "2024-12-15") correctly names the first two parameters and omits the default one.
  3. Step 3: Identify invalid calls

    Options B and C mix positional and named arguments incorrectly; D names all but unnecessarily names the default parameter.
  4. Final Answer:

    reserveSeat(name = "Emma", eventDate = "2024-12-15") -> Option A
  5. Quick Check:

    Omit default parameters or name them explicitly. [OK]
Quick Trick: Omit default params or name them explicitly [OK]
Common Mistakes:
MISTAKES
  • Mixing positional and named arguments incorrectly
  • Providing default parameters unnecessarily
  • Incorrect argument order when mixing named and positional

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes