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
-
A1, 3
-
B2, 5
-
C3, 4
-
D4, 5
-
ENone of these
Answer
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:
protectedmembers are visible to derived classes.publicmembers are visible everywhere, including in derived classes.privatemembers are not visible outside the declaring class.static(and VB’sshared) 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