public— accessible from anywhere.private— accessible only within the same class or struct.protected— accessible within the same class and its derived classes.internal— accessible anywhere within the same assembly/project.protected internal— accessible from the same assembly or from derived classes in other assemblies.private protected— accessible only by derived classes within the same assembly.
Most restrictive → least restrictive:
private → private protected → protected / internal → protected internal → public
C# Access Modifiers — Interview Q&A
1. What is public****?
public means the member can be accessed from anywhere, including other assemblies.
The containing type itself must also be accessible.
2. What is private****?
private means the member can only be accessed inside the class or struct where it is declared.
Even derived classes cannot directly access it.
3. What is protected****?
protected means the member is accessible inside the declaring class and its derived classes.
Derived classes can access it even if they’re in another assembly.
4. What is internal****?
internal means the member is accessible anywhere within the same assembly.
Code in another assembly normally cannot access it.
5. What is **protected internal****?**It means the member is accessible from the same assembly OR from a derived class in another assembly.
Think of it as combining protected and internal with OR.
6. What is private protected****?
It means the member is accessible only to derived classes that are also in the same assembly.
Think of protected and internal combined with AND.
7. What’s the difference between protected internal and private protected****?
protected internal = same assembly OR derived class.private protected = same assembly AND derived class.
8. Can a derived class access a private member of its base class?
No. A private member can only be directly accessed by the class that declares it.
A derived class would need a protected/public method or property to interact with it.
9. Can a non-derived class access a protected member?
No. Being in the same assembly doesn’t automatically give access to a protected member.
The caller generally needs to be part of the inheritance hierarchy.
10. Can an internal member be accessed from another assembly?
Normally, no. internal limits accessibility to the same assembly.
One notable exception is friend assemblies using InternalsVisibleTo.
11. When would you use protected instead of **private****?**Use protected when derived classes need direct access to the member.
Otherwise, prefer private to maintain stronger encapsulation.
12. When would you use internal****?
Use internal when something should be shared across your assembly but shouldn’t be part of the public API.
It’s commonly useful for implementation details shared between classes.
**13. What is the default access modifier for class members?**Class members are private by default.
So int count; inside a class is effectively private int count;.
**14. What is the default access modifier for a top-level class?**A top-level class is internal by default.
So class Foo { } is effectively internal class Foo { }.
15. Can a top-level class be private or **protected****?**No. A top-level class can generally be public or internal.
private and protected make sense for nested types, not top-level types.
16. Can a nested class be private****?
Yes. Unlike top-level classes, nested classes can use modifiers such as private and protected.
A private nested class is accessible only within its containing type.
17. Which is more restrictive: protected internal or private protected****?
private protected is more restrictive because both conditions must be satisfied.
The caller must be in a derived class and in the same assembly.
18. What’s the order from most restrictive to least restrictive?
private → private protected → protected / internal → protected internal → public.
Note that protected and internal aren’t strictly more/less restrictive than each other—they allow different sets of callers.
⭐ Interview memory trick
protected internal → ORSame assembly OR derived class.
private protected → ANDSame assembly AND derived class.