All C++ programs are composed of following two fundamental elements:
· Program statements (code): This is the part of a program that performs actions and they are called functions.
· Program data: The data is the information of the program which affected by the program functions.
Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding.
C++ supports the properties of encapsulation and data hiding through the creation of user-defined types, called classes. We already have studied that a class can contain private, protected and public members. By default, all items defined in a class are private. For example:
return length * breadth * height;
double length;// Length of a box
double breadth;// Breadth of a box
double height;// Height of a box