Understand Data Encapsulation
Data encapsulation/ data hiding is an important feature of object oriented programming. The mechanism of hiding data is to put them in a class and make them private. The data is now hidden and safe from any accidental manipulations, i.e. no function (from outside the class) can change the member data. Actually there are two things you can hide: implementation of functions (to the user it doesn't matter as to how you've implemented a particular function) and data. In procedural programming it is possible to only hide the implementation details but you cannot hide/ protect data. OOP lets you achieve this. A simple example is the case of the 'car' (Explained in Data Abstraction, go through the next question). We don't want the user to directly access 'speed' and modify it. By making 'speed' private, we prevent the user from doing this.

Shakuntala GaurPosted May 30, 2012, 8:10 AM
I just wanted to explain the concept of Encapsulation, yes we can not call the private method from outside the class. how we just show the required info to the user inspiting of showing the unneccesary information.
Kind regards,
Shakuntala
vinod kumarPosted May 28, 2012, 10:43 AM
The method fnMultipl() is private ,how can it be called from outside of the class.
thanks,
vinod.
Shakuntala GaurPosted May 28, 2012, 8:50 AM
It is the ability of an object to hide its data and methods from the rest of the world. It is one of the fundamental principles of OOPs.
Say we create a class, named Calculations. This class may contain a few members in the form of properties, events, fields or methods. Once the class is created, we may instantiate the class by creating an object out of it. The object acts as an instance of this class, the members of the class are not exposed to the outer world directly, rather, they are encapsulated by the class.
For Example:
Public class Calculations
{
public void fnMultiply(int x, int y)
{
return x * y;
}
}
Calculations obj = new Calculations();
int Result;
Result = obj.fnMultiply(5,10);
Satyapriya NayakPosted May 28, 2012, 1:50 AM