Bird
0
0

Which of the following statements about instanceof is TRUE?

easy📝 Conceptual Q2 of 15
PHP - Inheritance and Polymorphism
Which of the following statements about instanceof is TRUE?
A<code>instanceof</code> can be used to check if a variable is null
B<code>instanceof</code> returns true if the object implements an interface
C<code>instanceof</code> only works with built-in PHP classes
D<code>instanceof</code> can check if a class exists
Step-by-Step Solution
Solution:
  1. Step 1: Review instanceof behavior with interfaces

    instanceof returns true if the object implements the interface.
  2. Step 2: Check other options

    It does not check null, class existence, or only built-in classes.
  3. Final Answer:

    instanceof returns true if the object implements an interface -> Option B
  4. Quick Check:

    instanceof works with interfaces = D [OK]
Quick Trick: instanceof works with classes and interfaces [OK]
Common Mistakes:
  • Trying to use instanceof on null variables
  • Assuming instanceof only works with classes
  • Confusing instanceof with function_exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes