Bird
0
0

Which of the following is the correct syntax to negate a boolean variable isActive in Kotlin?

easy📝 Syntax Q12 of 15
Kotlin - Operators and Expressions
Which of the following is the correct syntax to negate a boolean variable isActive in Kotlin?
A!isActive
Bnot isActive
CisActive!
D~isActive
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kotlin negation syntax

    In Kotlin, the NOT operator is written as ! before the variable.
  2. Step 2: Check each option

    !isActive uses !isActive which is correct. not isActive is invalid syntax, C places ! after variable which is wrong, D uses ~ which is bitwise NOT invalid for booleans.
  3. Final Answer:

    !isActive -> Option A
  4. Quick Check:

    Negate with ! before variable [OK]
Quick Trick: Put ! before variable to negate [OK]
Common Mistakes:
MISTAKES
  • Putting ! after variable
  • Using 'not' keyword incorrectly
  • Using bitwise ~ for negation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes