Bird
0
0

Identify the error in the following code:

medium📝 Debug Q6 of 15
PHP - Interfaces and Traits
Identify the error in the following code:
interface Config {
  private const TIMEOUT = 30;
}
AThe const keyword is not allowed in interfaces.
BInterfaces cannot have private constants.
CConstants must be initialized with a string.
DConstants must be declared as protected.
Step-by-Step Solution
Solution:
  1. Step 1: Check visibility of interface constants

    Interface constants are always public and cannot be private or protected.
  2. Step 2: Analyze the code

    Declaring private const inside interface causes a syntax error.
  3. Final Answer:

    Interfaces cannot have private constants. -> Option B
  4. Quick Check:

    Interface constants visibility = public only [OK]
Quick Trick: Interface constants cannot have private or protected visibility [OK]
Common Mistakes:
  • Trying to declare private or protected constants in interfaces
  • Confusing class constant rules with interface constants
  • Assuming const keyword is disallowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes