Bird
0
0

Given the Kotlin code below, what will be the output?

hard📝 Application Q15 of 15
Kotlin - Operators and Expressions
Given the Kotlin code below, what will be the output?
val a = 7
val b = 7
val c = 10
println((a == b) && (b < c))
Afalse
Btrue
C7
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the first comparison (a == b)

    Since both a and b are 7, a == b is true.
  2. Step 2: Evaluate the second comparison (b < c)

    Since 7 is less than 10, b < c is true.
  3. Step 3: Evaluate the logical AND

    Both conditions are true, so true && true is true.
  4. Final Answer:

    true -> Option B
  5. Quick Check:

    (7 == 7) && (7 < 10) = true [OK]
Quick Trick: Both conditions must be true for && to return true [OK]
Common Mistakes:
MISTAKES
  • Confusing && with || operator
  • Misreading comparison results
  • Expecting numeric output instead of boolean

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes