Abstraction in C++


Prev Tutorial Next Tutorial

Abstraction in C++

Abstraction is the concept of exposing only the required essential characteristics and behavior with respect to a context.

Hiding of data is known as data abstraction. In object oriented programming language this is implemented automatically while writing the code in the form of class and object.

Real life example of Abstraction

Abstraction shows only important things to the user and hides the internal details for example when we ride a bick, we only know about how to ride bick but can not know about how it work ? and also we do not know internal functionality of bick.

real life example of abstraction

Example of Abstraction in C++

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

class sum
{
// hidden data from outside world
private: int a,b,c;

public:
void add()
{
clrscr();
cout<<"Enter any two numbers: ";
cin>>a>>b;
c=a+b;
cout<<"Sum: "<<c;
}
};
void main()
{
sum s;
s.add();
getch();
}

Output

Enter any two number: 
4
5
Sum: 9

Note: Data abstraction can be used to provide security for the data from the unauthorized methods.

Note: Note: In C++ language data abstraction can be achieve by using class.


Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements