Bird
Raised Fist0

Why does C# allow protected members to be accessed only within the class and its derived classes?

hard🧠 Conceptual Q10 of Q15
C Sharp (C#) - Inheritance

Why does C# allow protected members to be accessed only within the class and its derived classes?

ATo enable controlled access for inheritance while hiding from unrelated classes.
BTo make members accessible to all classes in the same assembly.
CTo allow access only within the declaring class itself.
DTo make members accessible publicly without restrictions.
Step-by-Step Solution
Solution:
  1. Step 1: Understand purpose of protected modifier

    Protected is designed to allow derived classes to use base class members safely.
  2. Step 2: Contrast with other access levels

    It hides members from unrelated classes to maintain encapsulation and prevent misuse.
  3. Final Answer:

    To enable controlled access for inheritance while hiding from unrelated classes. -> Option A
  4. Quick Check:

    Protected = inheritance access control [OK]
Quick Trick: Protected controls inheritance access, hides from unrelated classes [OK]
Common Mistakes:
MISTAKES
  • Confusing protected with public or internal
  • Thinking protected is private
  • Ignoring encapsulation purpose

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes