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 Shape { public function area(); }
class Circle implements Shape {
public function area($radius) { return 3.14 * $radius * $radius; }
}
ACannot implement interface inside a class
BMissing interface keyword before class
CNo error, code is correct
DMethod signature mismatch: interface method has no parameters, class method has one
Step-by-Step Solution
Solution:
  1. Step 1: Compare method signatures

    Interface method area() has no parameters; class method area($radius) has one parameter.
  2. Step 2: Understand PHP rules

    Method signatures must match exactly; mismatch causes error.
  3. Final Answer:

    Method signature mismatch: interface method has no parameters, class method has one -> Option D
  4. Quick Check:

    Interface and class method signatures must match [OK]
Quick Trick: Method signatures must match interface exactly [OK]
Common Mistakes:
  • Ignoring parameter differences
  • Thinking interface keyword is needed before class
  • Believing interface cannot be implemented

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes