Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Basics and JVM Runtime
What will be the output of this Kotlin code?
fun main() {
    val name = "Kotlin"
    println("Hello, $name!")
}
AHello, $name!
BHello, name!
CHello, Kotlin!
DError: Variable not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand string interpolation

    Kotlin uses $variable inside strings to insert variable values.
  2. Step 2: Evaluate the print statement

    Here, $name is replaced by "Kotlin", so output is "Hello, Kotlin!".
  3. Final Answer:

    Hello, Kotlin! -> Option C
  4. Quick Check:

    String interpolation outputs variable value [OK]
Quick Trick: Use $variable to insert values in Kotlin strings [OK]
Common Mistakes:
MISTAKES
  • Printing literal $name instead of value
  • Syntax errors in string interpolation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes