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?
Why Protected? Isn't Protected still available for derived classes? While we must restrict access for derived classes and to base class. And Private is accessible only in the same class or struct
The Answer should be protected. The statement mentions that "The member should be available to base class and ANY DERIVED classes".
If they would have said "NESTED DERIVED "Classes then Private is the correct answer.
see the below statement from this link https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/inheritance :
Private members are visible only in derived classes that are nested in their base class. Otherwise, they are not visible in derived classes.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
cdc
Highly Voted 2 years, 6 months agoVarracosta
1 year, 1 month agovinx909
8 months, 2 weeks agoNamilopod
Most Recent 2 months agomisbelieving
2 months, 2 weeks agomk_dyn365
8 months agosamkaas
1 year, 5 months ago