Bird
0
0

Which of the following is the correct way to declare an abstract method in a PHP abstract class?

easy📝 Syntax Q12 of 15
PHP - Inheritance and Polymorphism
Which of the following is the correct way to declare an abstract method in a PHP abstract class?
Aabstract public function myMethod();
Bpublic function myMethod() {}
Cfunction abstract myMethod();
Dpublic abstract myMethod() {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall abstract method syntax

    In PHP, abstract methods are declared with the keyword abstract before the function signature and have no body (no curly braces).
  2. Step 2: Check each option

    abstract public function myMethod(); correctly declares an abstract method: abstract public function myMethod();. Options B and D have bodies or wrong order, and C uses incorrect syntax.
  3. Final Answer:

    abstract public function myMethod(); -> Option A
  4. Quick Check:

    Abstract method = abstract + no body [OK]
Quick Trick: Abstract methods have no body and use 'abstract' keyword [OK]
Common Mistakes:
  • Adding curly braces {} to abstract methods
  • Wrong keyword order or missing 'abstract'
  • Trying to implement method body in abstract method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes