Bird
0
0

Which of the following is the correct syntax to extend a class named Animal in PHP?

easy📝 Syntax Q12 of 15
PHP - Inheritance and Polymorphism
Which of the following is the correct syntax to extend a class named Animal in PHP?
Aclass Dog extends Animal {}
Bclass Dog inherits Animal {}
Cclass Dog implements Animal {}
Dclass Dog use Animal {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP class extension syntax

    To create a child class, PHP uses the syntax: class Child extends Parent {}.
  2. Step 2: Match the syntax with options

    class Dog extends Animal {} matches the correct syntax. The other options use incorrect keywords.
  3. Final Answer:

    class Dog extends Animal {} -> Option A
  4. Quick Check:

    Correct syntax uses 'extends' keyword [OK]
Quick Trick: Use 'extends' keyword exactly after class name [OK]
Common Mistakes:
  • Using 'inherits' instead of 'extends'
  • Confusing 'implements' with 'extends'
  • Using 'use' keyword for inheritance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes