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.