Bird
0
0

Identify the issue in this Kotlin code snippet:

medium📝 Debug Q6 of 15
Kotlin - Data Types
Identify the issue in this Kotlin code snippet:
val flag1 = true
val flag2 = false
val combined = flag1 or flag2
println(combined)
AThe 'or' operator should be '||' for logical OR
BVariables flag1 and flag2 must be mutable (var) instead of val
CThe println statement is missing parentheses
DThere is no issue; the code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand Kotlin logical operators

    In Kotlin, 'or' is a valid infix function for Boolean types that performs logical OR.
  2. Step 2: Confirm code correctness

    The code uses 'or' correctly as an infix function for Booleans, so it compiles and runs correctly.
  3. Final Answer:

    There is no issue; the code is correct -> Option D
  4. Quick Check:

    Using 'or' as infix function for Booleans is valid [OK]
Quick Trick: In Kotlin, 'or' can be used as infix function for Boolean OR [OK]
Common Mistakes:
MISTAKES
  • Confusing 'or' with bitwise OR on Int types
  • Assuming 'or' is invalid for Booleans
  • Thinking 'or' must be replaced with '||'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes