Bird
0
0

Find the problem in this PHP code snippet:

medium📝 Debug Q7 of 15
PHP - Interfaces and Traits
Find the problem in this PHP code snippet:
interface Printer { public function print(); }
class Document implements Printer {
public function print($text) { echo $text; }
}
AInterface methods cannot be public
BClass cannot implement more than one interface
CClass method has a parameter but interface method does not
DNo problem, code is valid
Step-by-Step Solution
Solution:
  1. Step 1: Check interface method signature

    Interface method print() has no parameters.
  2. Step 2: Check class method signature

    Class method print($text) has one parameter, causing mismatch.
  3. Final Answer:

    Class method has a parameter but interface method does not -> Option C
  4. Quick Check:

    Method signatures must match exactly [OK]
Quick Trick: Interface and class method parameters must match [OK]
Common Mistakes:
  • Thinking interface methods can't be public
  • Believing multiple interfaces are not allowed
  • Assuming parameter differences are allowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes