Software Development Fundamentals — Question 1
You are designing a class for an application. You need to restrict the availability of the member variable accessCount to the base class and to any classes that are derived from the base class.
Which access modifier should you use?
Answer options
- A. Internal
- B. Protected
- C. Private
- D. Public
Correct answer: C
Explanation
The correct answer is C, Private, because it restricts access to the member variable accessCount only to the class in which it is declared. While Protected would allow derived classes access, it does not restrict access from other classes outside the inheritance hierarchy, which is not the requirement. Internal and Public would allow broader access than intended.