Bird
0
0

Identify the error in this PHP code:

medium📝 Debug Q6 of 15
PHP - Interfaces and Traits
Identify the error in this PHP code:
interface Printer {
  public function print();
}

class Document implements Printer {
  // Missing print() method
}
AInterface Printer cannot have methods
BClass Document must implement print() method
CClass Document should extend Printer
DNo error, code is valid
Step-by-Step Solution
Solution:
  1. Step 1: Check interface method requirements

    Printer interface declares print() method.
  2. Step 2: Verify class implementation

    Document implements Printer but does not define print(), causing error.
  3. Final Answer:

    Class Document must implement print() method -> Option B
  4. Quick Check:

    Interface methods must be implemented [OK]
Quick Trick: Implement all interface methods to avoid errors [OK]
Common Mistakes:
  • Assuming interface methods are optional
  • Using extends instead of implements
  • Ignoring missing method errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes