Encapsulation in C++
Encapsulation is not C++ programming concept it is Object Oriented 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.
Syntax of Encapsulation
class class name
{
private:
datatype data;
public:
Member functions;
};
main()
{
classname objectname1,objectname2……………;
}
Example of Encapsulation
class Square
{
private:
int Num;
public:
void Get()
{
cout<<"Enter Number:";
cin>>Num;
}
void Show()
{
cout<<"Square Is:"<<Num*Num;
}
};
void main()
{
Square s;
s.Get();
s.Show();
getch();
}
No comments :
Post a Comment