Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q13 of 15
Kotlin - Basics and JVM Runtime
What will be the output of this Kotlin code?
fun main() {
    val greeting = "Hello"
    val name = "Anna"
    println("$greeting, $name!")
}
AHello, Anna!
B$greeting, $name!
Cgreeting, name!
DHello Anna
Step-by-Step Solution
Solution:
  1. Step 1: Understand string interpolation in Kotlin

    Kotlin uses $variable inside strings to insert variable values.
  2. Step 2: Apply interpolation to variables

    Here, $greeting becomes "Hello" and $name becomes "Anna".
  3. Final Answer:

    Hello, Anna! -> Option A
  4. Quick Check:

    String interpolation = Hello, Anna! [OK]
Quick Trick: Look for $variable inside strings for interpolation [OK]
Common Mistakes:
MISTAKES
  • Printing variable names instead of values
  • Missing commas or punctuation in output
  • Confusing Kotlin with other languages' string syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes