Bird
0
0

Which statement best describes the behavior of the parent keyword in PHP when used in a class hierarchy?

hard📝 Conceptual Q10 of 15
PHP - Inheritance and Polymorphism
Which statement best describes the behavior of the parent keyword in PHP when used in a class hierarchy?
AIt allows access to any ancestor class methods regardless of visibility
BIt allows access to static methods only
CIt allows access to sibling class methods
DIt allows access only to the immediate parent class methods respecting visibility
Step-by-Step Solution
Solution:
  1. Step 1: Understand scope of parent keyword

    The parent keyword accesses methods from the immediate parent class only.
  2. Step 2: Consider visibility rules

    Access respects visibility: private methods are not accessible via parent.
  3. Final Answer:

    It allows access only to the immediate parent class methods respecting visibility -> Option D
  4. Quick Check:

    parent keyword = immediate parent methods with visibility respected [OK]
Quick Trick: parent accesses immediate parent methods only, obeying visibility [OK]
Common Mistakes:
  • Assuming parent accesses all ancestors
  • Thinking parent accesses sibling methods
  • Believing parent only accesses static methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes