Bird
0
0

What will be the output of the following Kotlin code?

medium📝 Predict Output Q13 of 15
Kotlin - Variables and Type System
What will be the output of the following Kotlin code?
const val PI = 3.14
fun main() {
    println("Value of PI: $PI")
}
ACompilation error
BValue of PI: $PI
CValue of PI: 3.14
DValue of PI: 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand string interpolation in Kotlin

    The println statement uses $PI which means it will replace $PI with the value of the constant PI.
  2. Step 2: Check the constant value and output

    PI is declared as 3.14, so the output will be "Value of PI: 3.14" exactly.
  3. Final Answer:

    Value of PI: 3.14 -> Option C
  4. Quick Check:

    String interpolation replaces $PI with 3.14 [OK]
Quick Trick: Look for $variable inside strings for value substitution [OK]
Common Mistakes:
MISTAKES
  • Thinking $PI prints literally as $PI
  • Expecting integer output instead of float
  • Assuming compilation error due to const val usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes