Encapsulation is one of main four object-oriented programming concepts. Encapsulation is part of OOP where we decide on which depth level another user (programmer) can can dig in our code. Encapsulation is implemented by using access modifiers.
List of access modifiers:
- Protected internal
Public access modifier allows a class to expose its variables and methods to other classes/methods/objects/etc.. inside and and outside of it’s original class even outside of original assembly.
Private access modifier is default access modifier, meaning if we do not specify access modifier explicitly private is set as default one. Only methods of the same class can access its private members, meaning an instance of a class cannot access its private members L.
Protected and Protected internal access modifier are mostly used in implementing inheritance (one of the pillars of OOP). They allow child class to access variables and methods of base class. These access modifier will be explained later in Inheritance chapter.
Internal access modifier, same as public but is limited only to its root assembly. Internal is default access modifier of classes.