Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Variables and Type System
What will be the output of this Kotlin code?
const val GREETING = "Hello"
fun main() {
    println(GREETING)
}
ARuntime error
BGREETING
CCompilation error
DHello
Step-by-Step Solution
Solution:
  1. Step 1: Understand const val usage in code

    The constant GREETING is declared with value "Hello" and printed in main.
  2. Step 2: Predict output of println(GREETING)

    It prints the string value "Hello" stored in GREETING.
  3. Final Answer:

    Hello -> Option D
  4. Quick Check:

    Print const val value = A [OK]
Quick Trick: Printing const val prints its assigned value [OK]
Common Mistakes:
MISTAKES
  • Expecting variable name to print
  • Thinking const val causes compile error here
  • Confusing runtime and compile errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes