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?

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?

A.
Internal

B.
Protected

C.
Private

D.
Public



Leave a Reply 11

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


Omar

Omar

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!

erry

erry

Yes, private class only could be accessed on Base Class.

rachid belouche

rachid belouche

It’s not the right answer ,the right is protected.

SirIsaac007

SirIsaac007

B. which is “Protected” is the correct answer..
someone please correct this..

mandisa

mandisa

C is the correct answer of which its Private

DB7

DB7

No, B is the correct answer. Never will a derived class have access to a private member of its base class. Only Protected gives both (at the most restricted level).

Taimur

Taimur

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.

ashu

ashu

chutiyo sahi answer submit kia karo

Ankit Tyagi

Ankit Tyagi

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.