Bird
0
0

Which of the following Kotlin expressions correctly checks if two variables refer to the exact same object?

easy📝 Syntax Q12 of 15
Kotlin - Operators and Expressions
Which of the following Kotlin expressions correctly checks if two variables refer to the exact same object?
A<code>a === b</code>
B<code>a != b</code>
C<code>a.equals(b)</code>
D<code>a == b</code>
Step-by-Step Solution
Solution:
  1. Step 1: Identify the operator for referential equality

    In Kotlin, === checks if two variables point to the exact same object in memory.
  2. Step 2: Confirm other options

    == and .equals() check structural equality, and != checks inequality, so they don't check referential equality.
  3. Final Answer:

    a === b -> Option A
  4. Quick Check:

    === means referential equality [OK]
Quick Trick: Use === to check if two variables are the same object [OK]
Common Mistakes:
MISTAKES
  • Using == instead of === for object identity
  • Confusing .equals() with ===
  • Assuming != checks referential equality

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes