Recall & Review
beginner
What does it mean to extend a class in PHP?Extending a class means creating a new class that inherits properties and methods from an existing class. This helps reuse code and add new features.Click to reveal answer
beginner
How do you declare a class that extends another class in PHP?Use the <code>extends</code> keyword. For example: <br><code>class ChildClass extends ParentClass { }</code>Click to reveal answer
beginner
Can a child class override a method from its parent class?Yes, a child class can provide its own version of a method defined in the parent class by defining a method with the same name.Click to reveal answer
intermediate
What keyword allows a child class to call the parent class's method it overrides?The
parent:: keyword is used to call the parent class's method from the child class.Click to reveal answer
beginner
Why is extending classes useful in programming?
It helps avoid repeating code, makes programs easier to maintain, and allows adding or changing features without rewriting everything.
Click to reveal answer
Which keyword is used to create a class that inherits from another class in PHP?
✗ Incorrect
The
extends keyword is used to inherit from a parent class in PHP.If a child class has a method with the same name as its parent, what happens when you call that method on the child?
✗ Incorrect
The child's method overrides the parent's method and runs instead.
How can a child class call the original method from its parent class it has overridden?
✗ Incorrect
The
parent::method() syntax calls the parent class's method.Which of these is NOT a benefit of extending classes?
✗ Incorrect
Extending classes usually does not slow down programs; it helps organize code better.
What happens if a child class does not define a method that exists in the parent class?
✗ Incorrect
If the child class lacks the method, PHP uses the parent's method automatically.
Explain in your own words what it means to extend a class in PHP and why it is useful.
Think about how a child class can use and change what the parent class has.
You got /5 concepts.
Describe how method overriding works when extending classes in PHP and how to call the parent method from the child.
Focus on what happens when both classes have a method with the same name.
You got /4 concepts.