Which access modifier should you use for the GetData() method?

An application includes a class named Person. The Person class includes a method named GetData.
You need to ensure that the GetData() from the Person class.
Which access modifier should you use for the GetData() method?

An application includes a class named Person. The Person class includes a method named GetData.
You need to ensure that the GetData() from the Person class.
Which access modifier should you use for the GetData() method?

A.
Internal

B.
Protected

C.
Private

D.
Protected internal

E.
Public

Explanation:
Protected – The type or member can be accessed only by code in the same class or structure, or in a
class that is derived from that class.
http://msdn.microsoft.com/en-us/library/ms173121.aspx
The protected keyword is a member access modifier. A protected member is accessible within its
class and by derived class instances.



Leave a Reply 7

Your email address will not be published. Required fields are marked *


sv1slim

sv1slim

The question is missing something. If expression is “You need to ensure that the GetData() can be accessed from the Person class only” then answer is C: Private.

Pete

Pete

Some words are missing in the 2nd sentence.

anii

anii

Assuming the answer is correct (B Protected), the question should include “You need to ensure that the GetData() method can be used only by the Person class or a class derived from the Person class.”

YouCrackedMeUp

YouCrackedMeUp

If this would be the case then the answer is
D. Protected internal

gabriel_logan

gabriel_logan

If this would be the case then the answer is
B. Protected

@YouCrackedMeUp
“A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member.”
“Internal types or members are accessible only within files in the same assembly”
Protected Internal => (Protected || Internal)
So since there was no mention of assemblies in the question, the most accurate answer would be B. Protected