The public/private access modifiers are straightforward: public means everything has access while private means only the class has access. The internal/protected access modifiers are a little more complicated.
- Use internal when you want to block access to everything outside of the assembly.
- Use protected when you want to block access to everything except for the class and its subclasses.
In other words, internal means it’s “private” to the assembly and protected means it’s “private” to the class and its subclasses. To illustrate the difference, I’ll show diagrams.
First, the following diagram shows a class with an internal method.
The internal method is part of the Bird assembly. Everything in this assembly has access to this method. Nothing outside out of this assembly has access.
Now take a look at the following diagram showing a class with a protected method.
The protected method is defined in the Bird class. Only the Bird class and its subclasses (Cardinal and Chickadee) have access to this method. It’s “private” to the class where it’s defined and in its subclasses. Notice that the Cardinal subclass is in another assembly and even it has access to the protected method.