Encapsulation (OOP principle)




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 userAbstraction and encapsulation are related features in object oriented programming. Abstraction allows making relevant information visible and encapsulation enables a programmer to implement the desired level of abstraction.


Encapsulation is implemented by using access specifiers.

C# supports the following access specifiers:
  • 1. Public
  • 2. Private
  • 3. Protected
  • 4. Internal &
  • 5. Protected internal
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.
 
 

Leave a Reply