Bird
0
0

Which statement best describes constructor inheritance behavior in PHP when a child class defines its own constructor?

easy📝 Conceptual Q10 of 15
PHP - Inheritance and Polymorphism
Which statement best describes constructor inheritance behavior in PHP when a child class defines its own constructor?
AThe child class constructor automatically calls the parent constructor before executing.
BThe child class constructor must explicitly call the parent constructor to inherit it.
CThe parent constructor is ignored and cannot be called if the child defines its own.
DPHP merges parent and child constructors into one automatically.
Step-by-Step Solution
Solution:
  1. Step 1: Understand PHP constructor inheritance rules

    If a child class defines its own constructor, the parent constructor is NOT called automatically.
  2. Step 2: How to inherit parent constructor

    The child must explicitly call parent::__construct() to run the parent constructor.
  3. Final Answer:

    The child class constructor must explicitly call the parent constructor to inherit it. -> Option B
  4. Quick Check:

    Explicit call needed for parent constructor inheritance [OK]
Quick Trick: Explicitly call parent::__construct() to inherit parent constructor [OK]
Common Mistakes:
  • Assuming automatic parent constructor call
  • Thinking constructors merge automatically
  • Believing parent constructor is ignored

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes