- In general, encapsulation is a process of wrapping different units of code in one place or in a single unit, such as class.
- Encapsulation also achieves data hiding as all the members are other from different classes.
- In C#, we can bundle data members and member functions that operate together inside a single class.
using System;
// Class Box have both data memebers and member functions.
class Box{
int l, b, h;
public void enter()
{
Console.WriteLine("Enter the length: ");
l = Console.Readline();
Console.WriteLine("Enter the breadth: ");
b = Console.Readline();
Console.WriteLine("Enter the height: ");
h = Console.Readline();
}
public void volume()
{
int vol = l*b*h;
Console.WriteLine("Volume of box is: ",vol);
}
}