Bird
0
0

Why does PHP allow private properties to be declared with the same name in both parent and child classes without conflict?

hard📝 Conceptual Q10 of 15
PHP - Classes and Objects
Why does PHP allow private properties to be declared with the same name in both parent and child classes without conflict?
ABecause private properties are scoped only to their own class, not inherited
BBecause PHP merges private properties from parent and child classes
CBecause private properties become public in child classes
DBecause PHP treats private properties as static
Step-by-Step Solution
Solution:
  1. Step 1: Understand private property scope

    Private properties belong only to the class where they are declared and are not inherited by child classes.
  2. Step 2: Explain why same names don't conflict

    Since each class has its own separate private property, they do not conflict even if names are the same.
  3. Final Answer:

    Because private properties are scoped only to their own class, not inherited -> Option A
  4. Quick Check:

    Private properties are class-scoped, no inheritance [OK]
Quick Trick: Private properties are unique to each class, no inheritance [OK]
Common Mistakes:
  • Thinking private properties are inherited
  • Assuming PHP merges private properties
  • Confusing private with protected

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes