Bird
0
0

Which of the following is the correct syntax for a PHP class implementing two interfaces named FirstInterface and SecondInterface?

easy📝 Syntax Q12 of 15
PHP - Interfaces and Traits
Which of the following is the correct syntax for a PHP class implementing two interfaces named FirstInterface and SecondInterface?
Aclass MyClass extends FirstInterface, SecondInterface {}
Bclass MyClass implements FirstInterface, SecondInterface {}
Cclass MyClass implements FirstInterface SecondInterface {}
Dclass MyClass uses FirstInterface, SecondInterface {}
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct keyword for interfaces

    PHP uses the keyword implements to indicate a class uses interfaces.
  2. Step 2: Check syntax for multiple interfaces

    Multiple interfaces are listed separated by commas after implements.
  3. Final Answer:

    class MyClass implements FirstInterface, SecondInterface {} -> Option B
  4. Quick Check:

    implements + comma-separated interfaces = correct syntax [OK]
Quick Trick: Use 'implements' and commas to list interfaces [OK]
Common Mistakes:
  • Using 'extends' instead of 'implements' for interfaces
  • Missing commas between interface names
  • Using 'uses' keyword incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes