A Program to access the values of 'Private data members' :-


(using public member functions and object of that class)
# Simple program based on 'Encapsulation' Concept:-

#include<iostream.h>
#include<conio.h>

class sum
{
private:
int a,b,c;
public:

void add()
{
cout<<"Enter two numbers:";
cin>>a>>b;
c=a+b;
cout<<"Sum="<<c;
}
};

void main()
{
clrscr();
sum s;
s.add();
getch();
}

Output:


Enter two numbers:6
14
Sum=20

			

Previous Next