PrepAway - Latest Free Exam Questions & Answers

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() method can be used only by the Person class and
not by any class derived from the Person class.
Which access modifier should you use for the GetData() method?

PrepAway - Latest Free Exam Questions & Answers

A.
Public

B.
Protected internal

C.
Internal

D.
Private

E.
Protected

Explanation:
The GetData() method should be private. It would then only be visible within the Person
class.

One Comment on “Which access modifier should you use for the GetData() method?

  1. PaulC says:

    D is correct. Private method is accessible only from class itself.

    other options:

    public – accessible from everywhere
    protected – accessible from class and its derivates
    internal – accessible only within the same assembly
    protected internal – combination of those two




    5



    0

Leave a Reply