Bird
0
0

Which of the following is the correct way to declare an interface named Vehicle in PHP?

easy📝 Syntax Q12 of 15
PHP - Interfaces and Traits
Which of the following is the correct way to declare an interface named Vehicle in PHP?
Aclass Vehicle { public function start(); }
Binterface Vehicle { public function start(); }
Cinterface Vehicle { function start() {} }
Dinterface Vehicle { public function start() {} }
Step-by-Step Solution
Solution:
  1. Step 1: Recall interface method declaration rules

    In interfaces, methods are declared without code blocks (no curly braces with code).
  2. Step 2: Check each option

    'interface Vehicle { public function start(); }' declares interface and method without code, which is correct. Declarations with method bodies '{}' are wrong. Using 'class' instead of 'interface' is incorrect.
  3. Final Answer:

    interface Vehicle { public function start(); } -> Option B
  4. Quick Check:

    Interface methods have no body [OK]
Quick Trick: Interface methods end with semicolon, no braces [OK]
Common Mistakes:
  • Adding method bodies inside interfaces
  • Using class keyword instead of interface
  • Omitting semicolon after method declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes