Access modifiers are used to control the access to an object or to a function/method. This is a main part of the concept of Abstraction.
Different programming languages use different access modifiers. Here are some examples:
Java
Java has 4 access modifiers.
private
- These attributes can be accessed only inside the class.protected
- These attributes can be accessed by sub classes and classes from the same package.package
- These attributes can be accessed by the classes within the same package only.public
- These attributes can be accessed by everybody.C++
C++ has 3 access modifiers.
private
- These attributes can be accessed only inside the class.protected
- These attributes can be accessed by derived classes.public
- These attributes can be accessed by everybody.C#
C# has 5 access modifiers
private
- These attributes can be accessed only inside the class.protected internal
- These attributes can be accessed by same assembly and derived classes.protected
- These attributes can be accessed by derived classes.public internal
- These attributes can be accessed by the classes within the same assembly.public
- These attributes can be accessed by everybody.