Recall & Review
beginner
What is method overriding in PHP?
Method overriding in PHP is when a child class defines a method with the same name as a method in its parent class, replacing the parent's method behavior.Click to reveal answer
beginner
Why do we use method overriding?
We use method overriding to change or extend the behavior of a method inherited from a parent class, allowing child classes to customize functionality.
Click to reveal answer
intermediate
How do you call the parent class method inside an overridden method in PHP?You use <code>parent::methodName()</code> inside the child class method to call the parent class's version of the method.Click to reveal answer
beginner
What happens if the child class does not override a method from the parent class?If the child class does not override the method, it inherits and uses the parent's method as is.Click to reveal answer
intermediate
Can private methods be overridden in PHP?
No, private methods cannot be overridden because they are not accessible to child classes.
Click to reveal answer
What keyword is used to call the parent class method inside an overridden method in PHP?
✗ Incorrect
In PHP,
parent::methodName() calls the parent class's method.If a child class overrides a method, which method is executed when called on the child object?
✗ Incorrect
The child class method overrides the parent method and is executed.
Can a private method in a parent class be overridden by a child class in PHP?
✗ Incorrect
Private methods are not visible to child classes, so they cannot be overridden.
What happens if a child class does not override a method from its parent?
✗ Incorrect
The child class inherits and uses the parent's method if it does not override it.
Which of these is a reason to override a method?
✗ Incorrect
Overriding lets you change or extend the behavior of an inherited method.
Explain method overriding in PHP and how it helps in object-oriented programming.
Think about how child classes can change what they inherit.
You got /4 concepts.
Describe how to call a parent class method from an overridden method in PHP and why you might want to do that.
Sometimes you want to add to the parent's method, not just replace it.
You got /3 concepts.