Qus :- What is Encapsulation ?
Ans : – Encapsulation, in the context of C#, refers to an object’s ability to hide data and behavior that are not necessary to its user. Abstraction and encapsulation are related features in object oriented programming. Abstraction allows making relevant information visible and encapsulation enables a programmer to .
Encapsulation is implemented by using access specifiers.
1. Public : Public access specifier allows a class to expose its member variables and member functions to other functions and objects.
2. Private : Private access specifier allows a class to hide its member variables and member functions from other functions and objects.
Only and only functions of the same class can access its private members.
3. Protected : Protected access specifier allows a child class to access the member variables and member functions of its base class.
4. Internal : Any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.
5. Protected internal : The protected internal access specifier allows a class (except a child class within the same application ) to hide its member variables and member functions from other class objects and functions.