Bird
0
0

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

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

    PHP uses the keyword extends to inherit from another class.
  2. Step 2: Check each option

    Only class Car extends Vehicle {} uses the correct syntax: class Car extends Vehicle {}.
  3. Final Answer:

    class Car extends Vehicle {} -> Option B
  4. Quick Check:

    Extending syntax = class Child extends Parent [OK]
Quick Trick: Use 'extends' keyword to inherit a class in PHP [OK]
Common Mistakes:
  • Using 'inherits' instead of 'extends'
  • Using colon ':' like other languages
  • Omitting 'extends' keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes