Bird
0
0

Which of the following is the correct syntax to check if obj is NOT an Int in Kotlin?

easy📝 Syntax Q3 of 15
Kotlin - Variables and Type System
Which of the following is the correct syntax to check if obj is NOT an Int in Kotlin?
Aif (obj != Int) { /* code */ }
Bif (obj !is Int) { /* code */ }
Cif (!obj is Int) { /* code */ }
Dif (obj is! Int) { /* code */ }
Step-by-Step Solution
Solution:
  1. Step 1: Understand negation with is operator

    Kotlin uses !is to check if an object is NOT a type.
  2. Step 2: Identify correct syntax

    if (obj !is Int) is correct; is! is invalid syntax.
  3. Final Answer:

    if (obj !is Int) { /* code */ } -> Option B
  4. Quick Check:

    Negation of type check = D [OK]
Quick Trick: Use !is to check NOT a type [OK]
Common Mistakes:
MISTAKES
  • Writing is! instead of !is
  • Using != for type check
  • Using parentheses incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes