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:
Step 1: Recall interface method declaration rules
In interfaces, methods are declared without code blocks (no curly braces with code).
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.
Final Answer:
interface Vehicle { public function start(); } -> Option B
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
Master "Interfaces and Traits" in PHP
9 interactive learning modes - each teaches the same concept differently