Bird
0
0

Which of the following is the correct syntax to declare a protected method named calculate in a PHP class?

easy📝 Syntax Q3 of 15
PHP - Classes and Objects
Which of the following is the correct syntax to declare a protected method named calculate in a PHP class?
Afunction protected calculate() {}
Bprivate function calculate() {}
Cpublic calculate() {}
Dprotected function calculate() {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall method declaration syntax

    Access modifier comes before the function keyword, then method name and parentheses.
  2. Step 2: Check each option

    "function protected calculate() {}" has wrong keyword order. "private function calculate() {}" uses private modifier. "public calculate() {}" misses "function" keyword. "protected function calculate() {}" is correct syntax.
  3. Final Answer:

    protected function calculate() {} -> Option D
  4. Quick Check:

    Correct syntax = protected function calculate() {} [OK]
Quick Trick: Access modifier before 'function' keyword [OK]
Common Mistakes:
  • Omitting 'function' keyword
  • Wrong order of keywords
  • Using invalid modifiers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes