C#.NET inheritance accessibility — which base-class members are accessible to derived classes? Choose all that apply among: 1) static 2) protected 3) private 4) shared (VB equivalent of static) 5) public

Difficulty: Easy

Correct Answer: 2, 5

Explanation:


Introduction / Context:
This item tests knowledge of which access modifiers allow a derived class to access base-class members in C#.



Given Data / Assumptions:

  • protected members are visible to derived classes.
  • public members are visible everywhere, including in derived classes.
  • private members are not visible outside the declaring class.
  • static (and VB’s shared) describe storage/dispatch, not accessibility by themselves.


Concept / Approach:
Accessibility is determined by access modifiers like public, protected, internal, etc. Whether a member is static or instance is orthogonal to accessibility; a member can be public static or protected static.



Step-by-Step Solution:

Protected (2) → accessible to derived classes → valid.Public (5) → accessible everywhere → valid.Private (3) → not accessible in derived classes → invalid here.Static/shared (1, 4) → not access levels; they do not by themselves grant access → eliminate.


Verification / Alternative check:
Create a base with protected and public members and access them from a derived type; attempting to access private will cause a compile error.



Why Other Options Are Wrong:
They include private or confuse static/shared with accessibility.



Common Pitfalls:
Assuming static implies global accessibility. It does not.



Final Answer:
2, 5

More Questions from Inheritance

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion