Bird
0
0

What is the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Null Safety
What is the output of this Kotlin code?
val text: String? = "Hello"
text?.let { println(it.lowercase()) }
Anull
BHELLO
Chello
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Check variable value and safe call

    text is "Hello", not null, so let block runs.
  2. Step 2: Apply lowercase function inside let

    it.lowercase() converts "Hello" to "hello" and prints it.
  3. Final Answer:

    hello -> Option C
  4. Quick Check:

    Safe call let runs and prints lowercase = hello [OK]
Quick Trick: let runs only if variable is not null [OK]
Common Mistakes:
MISTAKES
  • Expecting uppercase output
  • Thinking let runs if variable is null
  • Confusing lowercase() with uppercase()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes