I am very confused about encapsulation. My current concept of encapsulation is that it is only used for data hiding.
My code:
class Program
{
static void Main(string[] args)
{
Shape a;
a= new Shape();
a.Area = 4;
Console.WriteLine(a.Area);
}
}
class Shape
{
private int _area = 0;
private int _parameter = 0;
public int Area { get; set; }
public int Parameter { get; set; }
}
From what I understand, the private int variable _area
is now encapsulated. So, what encapsulation is doing here is by
using private access modifier, I can hide this variable; and
by using public property, I can initialize this variable without
using the class variable.
Is this what encapsulation is all about? Please correct me if I am wrong.