difference between keyword internal and protected?

Answers were Sorted based on User's Feedback



difference between keyword internal and protected?..

Answer / jebasingh luccas

Major different between these internal and protected
keyword reside on scope in which it can be accessible.
internal defines the scope with in the assembly and
protected defines the scope to the derived
(sub) class.

Is This Answer Correct ?    39 Yes 6 No

difference between keyword internal and protected?..

Answer / dotnetasit

The keywords 'internal' and 'protected' are access modifiers.
If any member in a class is qualified with access
modifier 'internal', then it is friend to the current assembly
but not outside of it. This means any member or class(but not
the dervied classes) within the current assembly can access it.

On the other hand, any member qualified with access
modifier 'protected' can be accessed by derived classes only.

I also want to tell about the combined access
modifier 'protected internal'. Any member qualified with
access modifier 'protected internal' is accessible to the
derived classes as well as to any member or class within the
same assembly. So in a way, this combined modifier extends the
scope of 'internal'.

Is This Answer Correct ?    25 Yes 2 No

difference between keyword internal and protected?..

Answer / g2

protected :
This tells that the member is accessible to the derived
class and, in case, the class is a partial class then the
member is accessible to all the other partial classes to
this class. As you can access a protected member declared
in a code behind, you can access it in its respective .aspx
page also. If the member is in a class which is further
derived, it (the member) is available to the derived class
also.

internal :
This tells that the member is accessible any where in the
current assembly or the namespace. It never means that it
has larger scope than the protected. There can be derived
class of a class in other namespaces also. Then the member
with 'protected' will be accessible there but not a member
with 'internal' identifier.

'protected internal' or 'internal protected' :
This combination of identifier is a hybrid of both
protected and internal. But it does not enlarge the
accessibility but shrinks the accessibility instead. It
makes the member accessible to the "DERIVED CLASSES WITHIN
THE CURRENT ASSEMBLY OR NAMESPACE".

Is This Answer Correct ?    9 Yes 13 No

difference between keyword internal and protected?..

Answer / pawan

protected and internal can be accessed in the derived class
which can be in different namspaces.

Protected can not be accessed using object, it dosen't
matter whether it is in same or different namespace.

Only internal method will be accible using object

Is This Answer Correct ?    1 Yes 5 No

difference between keyword internal and protected?..

Answer / ghouse basha s

These are access specifiers,
Internal means methods and properties will be accessible to
Classes in the Assembly
Protected means methods and properties will be accessible to
classes and in the derived assembly

Is This Answer Correct ?    7 Yes 21 No

Post New Answer

More C Sharp Interview Questions

Why do we need interfaces?

2 Answers   HCL,


Explain synchronous and asynchronous operations?

0 Answers  


Define strong name in c#?

0 Answers  


What is the difference between namespace and class in c#?

0 Answers  


What is a console file?

0 Answers  






What does the initial catalog parameter define in the connection string?

0 Answers  


Are private members inherited in c#?

0 Answers  


Explain more on CLR

0 Answers  


What is int tryparse in c#?

0 Answers  


Why we use anonymous methods in c#?

0 Answers  


What are the three types of predicates?

0 Answers  


Explain the three services model (three-tier application).

3 Answers   4Cplus,


Categories