Bird
0
0

Which of the following is the correct syntax to call a parent class constructor inside a child class constructor in PHP?

easy📝 Syntax Q3 of 15
PHP - Inheritance and Polymorphism
Which of the following is the correct syntax to call a parent class constructor inside a child class constructor in PHP?
Aparent::__construct();
Bparent::construct();
Cparent->construct();
Dparent->__construct();
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP constructor naming

    PHP constructors are named __construct with two underscores.
  2. Step 2: Correct syntax to call parent constructor

    To call the parent constructor, use parent::__construct(); with double colon and double underscores.
  3. Final Answer:

    parent::__construct(); -> Option A
  4. Quick Check:

    Parent constructor call = parent::__construct() [OK]
Quick Trick: Use double colon and double underscores for parent constructor [OK]
Common Mistakes:
  • Using single underscore or wrong method name
  • Using arrow (->) instead of double colon (::)
  • Calling parent constructor without parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes