Now to show the behavior of how these class members are exposed to another class depending upon their scope defined via modifier/specifier and when we create an object or inherit from the preceding created class named "AccessModifier".
Now to use this class and class members we need to either create an object or inherit from this class.
Object Creation
Let's see what happens if we decide to create an object of the class "AccessModifier" shown in the code above. As per the rule private and protected must not be visible via an object?
Showing members available when an object is created of the given class.
As you can see in the intellisense popup that private and protected are not visible. private is not shown due to its limited scope within the class but the key thing here is that protected is not being displayed by an object since protected members are only available via inheritance.
However, protected internal is visible because it's a mix of two keywords and in the case of class instantiation, in other words object creation internal is showing its effect.
Members shown: internal, public, protected internal.
Members NOT shown: private, protected.
Inherit from Class
So if we derive another class "CallAccessModifier" from the parent class " AccessModifier " then "private" type members will not be visible because its considered as outside the scope of parent class.
But "protected" members are the ones that become available only during the inheritance (when a child is derived from a parent class) as shown via image below.
Showing class members availability through inheritance.
Note: The "
this" keyword refers to the current instance of the class and accesses its members. In the image above this keyword shows all the available members with the class.
If you notice in the preceding shown image it clearly shows all the protected members are visible due to virtue of inheritance, along with other members with scope defined as internal, public and protected internal.
However, protected internal is visible because it's a mix of two keywords and in the case of inheritance protected is showing its effect.
Members shown: internal, public, protected and protected internal
Members NOT shown: private
YouTube Video
http://youtu.be/MWxU9OpQlvE