Bird
0
0

Which statement best explains why PHP allows traits but not multiple inheritance?

hard📝 Conceptual Q10 of 15
PHP - Interfaces and Traits
Which statement best explains why PHP allows traits but not multiple inheritance?
AMultiple inheritance is not supported because interfaces cover all use cases.
BTraits provide code reuse without the complexity of multiple inheritance.
CTraits are faster than multiple inheritance.
DTraits enforce strict type checking unlike multiple inheritance.
Step-by-Step Solution
Solution:
  1. Step 1: Understand PHP's design choice

    PHP avoids multiple inheritance to prevent complexity and ambiguity in method resolution.
  2. Step 2: Role of traits

    Traits allow code reuse across classes without inheritance hierarchy issues, providing a simpler alternative.
  3. Final Answer:

    Traits provide code reuse without the complexity of multiple inheritance. -> Option B
  4. Quick Check:

    Traits simplify code reuse, avoiding multiple inheritance problems [OK]
Quick Trick: Traits avoid multiple inheritance complexity [OK]
Common Mistakes:
  • Thinking traits improve performance
  • Believing interfaces replace multiple inheritance
  • Confusing traits with type checking features

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes