---
title: "Access Modifier"  
description: "Access modifiers are an integral part of object – orientedprogramming. They support the concept of encapsulation, which promotes the ideaof hiding fun"  
author: "Uttam Misra"  
published: 2010-10-07  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/13/access-modifier  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# Access Modifier

[Access modifiers](https://www.mindstick.com/articles/338838/explain-access-modifiers-in-java) are an integral part of object – orientedprogramming. They support the concept of [encapsulation](https://www.mindstick.com/articles/12229/encapsulation-and-access-specifier), which promotes the ideaof hiding functionality. Access modifiers allow you to define who does ordoesn’t have access to certain features.\

##### In C# there are five different types of access Modifiers.

| ##### Modifier | ##### Description |
| --- | --- |
| Public | There is no restriction on accessing public members. |
| Private | Access is limited to within the class [definition](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat). This is the default access modifier types if none is formally specified. |
| Protected | Access is limited to within the class definition and any class that inherits from the class. |
| Internal | Access is limited exclusively to classes defined with in the [current project](https://answers.mindstick.com/qa/94412/what-are-the-biggest-problems-you-have-faced-while-working-in-a-current-project) [assembly](https://www.mindstick.com/articles/25/global-assembly-cache). |
| Protected internal | Access is limited to the current assembly and types derived from the containing class. All members in current project and all members in [derived class](https://answers.mindstick.com/qa/30686/what-is-a-base-class-and-derived-class) can access the variables. |

Public: The public keyword is an accessmodifier for types and type members. Public access is the most permissiveaccess level.

There are no [restrictions](https://www.mindstick.com/news/2343/a-handbook-for-social-media-parental-restrictions) on accessing public members.

## Accessibility:

*can be accessed by objects of the class

*Can be accessed by derived classes

Example:

```
Class accessmod{Public int num1;}Static void main(){Accessmod obj1=new accessmod();Obj1.num1=100;Console.WriteLine(“Number one value in main{0}”,ob1.num1)Console.ReadLine();}}}
```

Private:

Private access is the least permissive access level.

Private members are accessible only within the body of theclass or the struct in which they are declared.

## Accessibility:

*cannot be accessed by object

*Cannot be accessed by derived classes

Example:

```
Class accessmod{public  int num1;int num2;}Static noid main()Accessmod obj=new accessmod();Obj.num1=100;Obj.num2=20;Console.WriteLine(“Number one values in main {0}”,obj.num1);Console.ReadLine();}}
```

Protected

A protected member is accessible from within the class inwhich it is declared, and from within any class derived from class thatdeclared this member.

A protected member of class member of a [base class](https://www.mindstick.com/blog/116/base-class-initilization) isaccessible in a derived class only if the access [takes place](https://yourviews.mindstick.com/view/81718/pranab-mukherjee-death-how-last-rites-of-former-president-of-india-takes-place) through thederived class type.

## Accessibility:

*cannot be accessed by object

*Can be accessed by derived classes

Example:

```
Class base{Protected int num1;}Class drived:base{Public int num2;Static void main(){Base obj1=new  base();Derived obj2=new derived();Obj1.num1=20;Obj2.num2=90;Console.WriteLine(“Number two  values {0} ”,obj2.num2);Console.WriteLine(“Number one  values which is protected {0} ”,obj2.num1);Console.ReadLine();}}
```

##### Internal:

- The internal keyword is an access modifier for types and type members. We can declare a class as internal or its member as internal. Internal members are accessible only within files in the same assembly (.dll).
- In other words, access is limited exclusively to classes defined within the current project assembly.

[Accessibility](https://www.mindstick.com/blog/304975/why-image-alt-text-matters-for-seo-and-accessibility):

In same assembly (public)

- Can be accessed by objects of the class
- Can be accessed by derived classes

In other assembly (internal)

- Cannot be accessed by object
- Cannot be accessed by derived classes

##### Protected internal

The protected internalaccessibility means protected OR internal, not protected AND internal. In otherwords, a protected internal member is accessible from any class in the sameassembly, including derived classes. The protected internal access modifierseems to be a confusing but is a union of protected and internal in terms ofproviding access but not restricting. It allows:

- Inherited types, even though they belong to a different assembly, have access to the protected internal members.
- Types that reside in the same assembly, even if they are not derived from the type, also have access to the protected internal members.

---

Original Source: https://www.mindstick.com/blog/13/access-modifier

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
