Data Abstraction in C++

05 min read

Abstraction is the concept of showcasing only the required things to the outside world while hiding the details. Hiding of data is known as data abstraction. In the object-oriented programming language, this is implemented automatically while writing the code in the form of class and object.

Example:

Abstraction displays only the important things to any user and hides all the internal details. For example, when we ride a bike, we only know how to ride bike but cannot know as to how it works and also we do not know the internal functionality of bike.

class result
{
private: int a,b,c;
public:
void add()
{
clrscr();
cout<<"Enter any two numbers: ";
cin>>a>>b;
c=a+b;
cout<<"Result: "<<c;
}
};
void main()
{
result s;
s.add();
getch();
}
POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error