
how encapsulation is achieved? if i write private variables in my source code, it will achieve encapsulation. this statement is true in all cases....

Encapsulation is achieved by declaring variables as Private in a class- this gives access to data to only member functions of the class. A next level of accessibility is provided by the Protected keyword which gives the derived classes the access to the member variables of the base class- a variable declared as Protected can at most be accessed by the derived classes of the class.