Bird
0
0

Which of the following is the correct syntax to call a parent class method named show inside a child class method?

easy📝 Syntax Q12 of 15
PHP - Inheritance and Polymorphism
Which of the following is the correct syntax to call a parent class method named show inside a child class method?
Aparent.show();
Bparent->show();
Cparent::show();
Dparent:show();
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP syntax for calling parent methods

    In PHP, to call a parent class method inside a child, use the scope resolution operator :: with parent.
  2. Step 2: Match the correct syntax

    The correct syntax is parent::methodName();, so for method show, it is parent::show();.
  3. Final Answer:

    parent::show(); -> Option C
  4. Quick Check:

    Use :: with parent to call methods [OK]
Quick Trick: Use double colon (::) to call parent methods [OK]
Common Mistakes:
  • Using arrow (->) instead of double colon (::)
  • Using dot (.) operator which is for strings
  • Using single colon (:) which is invalid syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes