Bird
0
0

Identify the error in this Kotlin code snippet:

medium📝 Debug Q14 of 15
Kotlin - Data Types
Identify the error in this Kotlin code snippet:
val x = true
val y = false
val result = x & y
println(result)
AUsing single & instead of && for logical AND
BMissing semicolon after println
CBoolean variables cannot be assigned like this
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check operator usage

    In Kotlin, logical AND uses &&, not single &. Single & is bitwise AND, not for Booleans.
  2. Step 2: Understand error cause

    Using & with Booleans causes a type mismatch error.
  3. Final Answer:

    Using single & instead of && for logical AND -> Option A
  4. Quick Check:

    Logical AND = &&, not & [OK]
Quick Trick: Use && for Boolean AND, not single & [OK]
Common Mistakes:
MISTAKES
  • Using & instead of && for logical AND
  • Thinking semicolon is required
  • Assuming Boolean assignment is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes