top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are the Access Modifiers in C# ?

+1 vote
253 views

Hai, friend anybody explain about the Access Modifiers in C#

posted Nov 17, 2014 by Vinitha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Different Access Modifier are - Public, Private, Protected, Internal, Protected Internal
Public – When a method or attribute is defined as Public , It can be accessed from any code in project. For example in the above Class “Employee” , getName(), setName() etc are public.
Private - When a method or attribute is defined as Private , It can be accessed by any code within the containing type only. For example in the above Class “Employee” , attributes name and salary can be accessed with in the Class Employee Only. If an attribute or class are defined without access modifiers , its default access modifier will be private.
Protected - When an attribute and methods are defined as protected, it can be accessed by any method in inherited classes and any method within the same class. The protected access modifier cannot be applied to class and interfaces. Methods and fields in a interface cannot be declared protected.
Internal – If an attribute or method is defined as Internal , Access is restricted to classes within the current project assembly
Protected Internal – If an attribute or method is defined as Protected Internal , Access is restricted to classes within the current project assembly and types derived from the containing class.

answer Nov 17, 2014 by Manikandan J
Similar Questions
+3 votes

By-default all the methods & variables in class are private.

In C#.net Main() method is private then how compiler access this Main() Method out side the class because compiler is not part of our program then how compiler access this Main() method?

Here we loose our data abstraction property ? Can anyone put some light on it?

...