Recall & Review
beginner
What is constructor inheritance in PHP?
Constructor inheritance means a child class can use the constructor method of its parent class to set up initial values or states.Click to reveal answer
beginner
How do you call a parent class constructor inside a child class in PHP?You use <code>parent::__construct()</code> inside the child class constructor to run the parent constructor.Click to reveal answer
intermediate
What happens if a child class defines its own constructor but does not call <code>parent::__construct()</code>?The parent constructor will NOT run automatically. The child constructor overrides it, so you must call the parent constructor explicitly if needed.
Click to reveal answer
beginner
True or False: If a child class does not define a constructor, it automatically inherits the parent's constructor in PHP.True. The child class will use the parent's constructor if it does not have its own.Click to reveal answer
beginner
Why might you want to call the parent constructor inside a child constructor?
To make sure the parent class sets up its part of the object correctly before the child adds or changes anything.Click to reveal answer
In PHP, how do you call the parent class constructor from a child class?
✗ Incorrect
In PHP,
parent::__construct() calls the parent class constructor.If a child class has no constructor, what happens when you create an object of that child class?
✗ Incorrect
If the child class has no constructor, PHP uses the parent's constructor automatically.
What happens if a child class defines a constructor but does NOT call
parent::__construct()?✗ Incorrect
The child constructor overrides the parent constructor, so only the child constructor runs unless you call
parent::__construct() explicitly.Why is constructor inheritance useful?
✗ Incorrect
Constructor inheritance helps child classes reuse the parent's setup code, avoiding repetition.
Which keyword is used to refer to the parent class in PHP?
✗ Incorrect
The keyword
parent refers to the parent class in PHP.Explain how constructor inheritance works in PHP and how to properly use it in a child class.
Think about when the parent's constructor runs and how to call it explicitly.
You got /3 concepts.
Describe a real-life example where calling a parent constructor from a child class is important.
Imagine building a car where the base car sets wheels and engine, and the child adds special features.
You got /3 concepts.