Encapsulation In C++
Encapsulation
is a process of combining data members and functions in a single unit called
class. This is to prevent the access to the data directly, the access to them
is provided through the functions of the class. It is one of the popular
feature of Object
Oriented Programming(OOPs) that helps
in data hiding.
Fig: Encapsulation In C++ |
Program:
#include<iostream.h>
#include<conio.h>
class emp
{
private:
int a,b,c;
public:
emp()
{
a=b=c=0;
}
void get()
{
cout<<”enter two number\n”;
cin>>a>>b;
}
void put()
{
c=a+b;
cout<<c;
}
};
void main()
{
emp a1;
a1.get();
a1.put();
getch();
}
Output:
Enter two number
30
40
70
No comments:
Post a Comment