- One of the key features of data hiding is achieved through private keywords
- The class members which have been declared private can be accessed only within from the class not from outside.
- Only member function can access the private data.
- On the other hand public member can be accessed from outside the class.
- By default all the members of the class are private.
- The binding of data and function together into a single type class is referred as Encapsulation.
class item
{
Private:
Int number;
Float cost;
Public:
Void getdata(int a , float b);
Void putdata();
};
- Here the name of class is item.
- It contains two data members and two function members.
- The two data members number and cost are private and can accessed by member function getdata and putdata only.
Tags:
Cpp