Bird
0
0

What is the output of this Kotlin code?

medium📝 Predict Output Q13 of 15
Kotlin - Control Flow as Expressions
What is the output of this Kotlin code?
val age = 18
val status = if (age >= 18) "Adult" else "Minor"
println(status)
AMinor
BAdult
C18
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Check the condition age >= 18

    Since age is 18, the condition age >= 18 is true.
  2. Step 2: Determine the assigned value to status

    Because the condition is true, status is assigned "Adult".
  3. Final Answer:

    Adult -> Option B
  4. Quick Check:

    Condition true assigns "Adult" [OK]
Quick Trick: If condition true, if-else expression returns first value [OK]
Common Mistakes:
MISTAKES
  • Assuming >= 18 is false for 18
  • Printing age instead of status
  • Confusing syntax causing compile error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes