Bird
0
0

Given the class below, which code correctly prints the constant STATUS without creating an object?

hard📝 Application Q15 of 15
PHP - Classes and Objects
Given the class below, which code correctly prints the constant STATUS without creating an object?
class Server {
    const STATUS = 'Online';
}
Aecho Server->STATUS;
Becho Server::STATUS;
Cecho $server::STATUS;
Decho Server::status;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct constant access syntax

    Constants are accessed using the class name and the scope resolution operator :: with the exact constant name in uppercase.
  2. Step 2: Evaluate each option

    Server->STATUS is invalid because -> is for object properties; $server::STATUS is invalid because $server is undefined and constants should be accessed via class name; Server::status is wrong due to case sensitivity; only Server::STATUS is correct.
  3. Final Answer:

    echo Server::STATUS; -> Option B
  4. Quick Check:

    Use ClassName::CONSTANT with exact case [OK]
Quick Trick: Use ClassName::CONSTANT with exact uppercase name [OK]
Common Mistakes:
  • Using object operator -> instead of ::
  • Ignoring case sensitivity in constant names
  • Trying to access constants via undefined variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes