What is the default access modifier for class members in C#?
A. protected
B. public
C. private
D. internal
Answer: Option C
Solution (By Examveda Team)
The correct answer is C: private.Let's understand why:
* Access Modifiers control the visibility and accessibility of class members (like variables and methods).
* `public`: Means any code can access the member.
* `private`: Means only code within the same class can access the member.
* `protected`: Means the class itself and any classes that inherit from it (subclasses) can access the member.
* `internal`: Means code within the same assembly (a compiled set of code, like a .exe or .dll) can access the member.
If you don't explicitly specify an access modifier (like `public`, `private`, etc.) for a class member in C#, C# automatically assigns it the `private` access modifier.
This is a design choice to promote encapsulation - hiding the internal workings of a class and controlling access to its data. It makes the code more organized and maintainable.
Join The Discussion
Comments (1)
Related Questions on Introduction to C Sharp

The default access modifier is internal , it means if you donot specify any access modifier it can be used in the same assembly. hence the above "private " is a wrong option