Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q4 of 15
PHP - Classes and Objects
What will be the output of the following PHP code?
class Fruit {
    const COLOR = 'Red';
}
echo Fruit::COLOR;
ARed
BCOLOR
Cfruit::COLOR
DError: Undefined constant
Step-by-Step Solution
Solution:
  1. Step 1: Understand constant declaration and access

    The constant COLOR is declared with value 'Red' and accessed correctly using Fruit::COLOR.
  2. Step 2: Predict output

    Since the constant exists and is accessed properly, it prints 'Red'.
  3. Final Answer:

    Red -> Option A
  4. Quick Check:

    Class constant output = constant value [OK]
Quick Trick: Class constants print their value when accessed with :: [OK]
Common Mistakes:
  • Using lowercase class name in access
  • Expecting constant name as output
  • Forgetting to use :: operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes