PrepAway - Latest Free Exam Questions & Answers

Which access modifier should you use?

You are designing a class for an application. You need to restrict the availability of the
member variable accessCount to the base class and to any classes that are derived from the
base class.
Which access modifier should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
Internal

B.
Protected

C.
Private

D.
Public

11 Comments on “Which access modifier should you use?

  1. Omar says:

    This is not the correct answer. The correct answer is B. Protected. The private access modifier limits the availability of a class member to the containing class only while protected makes it also available for the derived classes.
    Please, don’t post incorrect answers!




    2



    0
  2. Ankit Tyagi says:

    public
    The type or member can be accessed by any other code in the same assembly or another assembly that references it. +
    private
    The type or member can be accessed only by code in the same class or struct.
    protected
    The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
    internal
    The type or member can be accessed by any code in the same assembly, but not from another assembly.




    0



    0

Leave a Reply