If a method is marked as protected internal who can access it?

  1. a. Access is limited to the current assembly

  2. b. Access is limited to the containing class or types derived from the containing class.

  3. c. Access is limited to the containing type

  4. d. Access is limited to the current assembly or types derived from the containing class.


Correct Option: D
Explanation:

To understand who can access a method marked as protected internal, the user needs to know about access modifiers in C#.

Now, let's go through each option and explain why it is right or wrong:

A. Access is limited to the current assembly: This option is partially correct. When a method is marked as internal, it can only be accessed within the same assembly. However, when a method is marked as protected internal, it can be accessed by derived types from any assembly as well as within the same assembly. Therefore, option A is incorrect.

B. Access is limited to the containing class or types derived from the containing class: This option is incorrect. When a method is marked as protected, it can be accessed by the containing class or types derived from the containing class. However, when a method is marked as protected internal, it can be accessed by derived types from any assembly as well as within the same assembly. Therefore, option B is incorrect.

C. Access is limited to the containing type: This option is incorrect. protected internal access modifier provides more accessibility than protected access modifier. When a method is marked as protected, it can be accessed by the containing class or types derived from the containing class. However, when a method is marked as protected internal, it can be accessed by derived types from any assembly as well as within the same assembly. Therefore, option C is incorrect.

D. Access is limited to the current assembly or types derived from the containing class: This option is correct. When a method is marked as protected internal, it can be accessed by derived types from any assembly as well as within the same assembly. Therefore, option D is the correct answer.

The Answer is: D

Find more quizzes: