- Data Hiding is also known as Encapsulation.
- Encapsulation is the process of combining data and function into a single unit called class.
- Data Hiding is the mechanism where the details of the class are hidden from the user.
- The user can perform only a restricted set of operations in the hidden member of the class.
- Encapsulation is a powerful feature that leads to information hiding,abstract data type and friend function.
- They encapsulate all the essential properties of the object that are to be created.
- Using the method of encapsulation the programmer cannot directly access the class.
Access Specifier:
There are three types of access specifier.They are
- Private :Within the block.
- Public:Whole over the class.
- Protected:Act as a public and then act as a private.
General Form:
class class name{
private:datatype data;public:Member functions;
};main(){
classname objectname1,objectname2……………;
}
Example:
class Square{
private:int Num;public:void Get() {cout<<"Enter Number:";cin>>Num;}void Display() {cout<<"Square Is:"<<Num*Num;}
};void main(){
Square Obj;Obj.Get();Obj.Display();getch()
}
No comments:
Post a Comment