Bird
0
0

Which of the following is the correct syntax to check if $obj is an instance of class Car?

easy📝 Syntax Q12 of 15
PHP - Inheritance and Polymorphism
Which of the following is the correct syntax to check if $obj is an instance of class Car?
Aif ($obj instance Car) {}
Bif ($obj is Car) {}
Cif (instanceof $obj Car) {}
Dif ($obj instanceof Car) {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct instanceof syntax

    The correct syntax is: variable instanceof ClassName, without extra keywords or rearrangement.
  2. Step 2: Check each option

    if ($obj instanceof Car) {} matches the correct syntax exactly. Others have wrong keywords or order.
  3. Final Answer:

    if ($obj instanceof Car) {} -> Option D
  4. Quick Check:

    Correct instanceof syntax [OK]
Quick Trick: Syntax is always: variable instanceof ClassName [OK]
Common Mistakes:
  • Using 'is' instead of 'instanceof'
  • Reversing order of variable and class
  • Adding extra keywords inside condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes