Bird
0
0

Which of the following is the correct syntax to make class Car inherit from class Vehicle in PHP?

easy📝 Syntax Q12 of 15
PHP - Inheritance and Polymorphism
Which of the following is the correct syntax to make class Car inherit from class Vehicle in PHP?
Aclass Car extends Vehicle {}
Bclass Car inherits Vehicle {}
Cclass Car Vehicle {}
Dclass Car : Vehicle {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP inheritance syntax

    In PHP, the keyword extends is used to inherit from another class.
  2. Step 2: Match syntax with options

    Only class Car extends Vehicle {} uses extends correctly to inherit from Vehicle.
  3. Final Answer:

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

    Inheritance keyword = extends [OK]
Quick Trick: Use 'extends' keyword to inherit in PHP [OK]
Common Mistakes:
  • Using 'inherits' instead of 'extends'
  • Omitting 'extends' keyword
  • Using ':' like other languages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes