I am reading few fundamental things of OOP. I am confused about encapsulation and abstraction. As per my understanding, Abstraction is a way of exposing only few things and hiding few. Encapsulation helps us to encapsulate the state of an object so that it is not accessible to the outside world and it can be accessed through internal methods. Hence they both are correlated. But i have read many times that encapsulation is achieved by using getter and setter while abstraction is achieved using abstract classes and interfaces. Now consider following code (C#)
class A
{
private int a;
public void print()
{
Console.WriteLine("Value of a = {0}", a);
}
}
class B
{
static void Main(string[] args)
{
A a = new A();
a.print();
}
}
In above code i have not used interfaces nor abstract class but still as per my understanding i have achieved abstraction here by not letting B class access variable a directly. By implementing encapsulation i made sure it is only accessible by using internal methods of A. So can you please help me clear the confusion?