Data Abstraction

Data abstraction in C plus plus program if we implement class with private and public members then it is an example of data abstraction.

Let’s see the simple example of data abstraction.

 
  • #include <iostream>  
  • using namespace std;  
  •  class Sum  
  • {  
  • privateint x, y, z;  
  • public:  
  • void add()  
  • {  
  • cout<<“Enter two numbers: “;  
  • cin>>x>>y;  
  • z= x+y;  
  • cout<<“Sum of two number is: “<<z<<endl;  
  • }  
  • };  
  • int main()  
  • {  
  • Sum sm;  
  • sm.add();  
  • return 0;  
  • }  

Output:

Enter two numbers:
3
6
Sum of two number is: 9