Bird
0
0

Which of the following correctly uses the is operator to verify if obj is an instance of Employee?

easy📝 Syntax Q3 of 15
C Sharp (C#) - Polymorphism and Abstract Classes
Which of the following correctly uses the is operator to verify if obj is an instance of Employee?
Aif (obj as Employee)
Bif (obj is Employee)
Cif (obj == Employee)
Dif (obj instanceof Employee)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the is operator

    The is operator checks if an object is compatible with a given type and returns a boolean.
  2. Step 2: Analyze options

    if (obj is Employee) uses the correct syntax: if (obj is Employee). if (obj as Employee) is invalid because as returns an object or null, not a boolean. if (obj == Employee) compares an object to a type, which is invalid. if (obj instanceof Employee) uses Java syntax, not C#.
  3. Final Answer:

    if (obj is Employee) -> Option B
  4. Quick Check:

    Correct syntax for is operator [OK]
Quick Trick: Use 'is' to check type compatibility [OK]
Common Mistakes:
MISTAKES
  • Using 'as' instead of 'is' for type checking
  • Comparing object directly to a type
  • Using Java syntax 'instanceof' in C#

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes