Abstraction

It is one of the most important features of oops, which has showing only essential information and hiding the internal details. In other we can say that in this type of programming essential data is shown to the user or outside class and unessential data is hidden. Members defined with a public access specifier are accessible throughout the program. Members defined with a private access specifier are not accessible throughout the program means private element of a class can be accessed only inside in its own class.

One Real life Example :

Let's take a real life example asssume that you are going to buy a car in showroom then you can know about company name, model name, colour,cost and oil type but you don't know about piston and its functionility, the person who made that model of car. For better understanding see the below example :

Example:

#include< iostream.h >
class car
{
public: //access specifier
void company()
{
cout<<"Renault"<<"\n";
}
public: //access specifier
void model()
{
cout<<"Duster"<<"\n";
}
public: //access specifier
void color()
{
cout<<"Red/brown/silver"<<"\n";
}
public: //access specifier
void cost()
{
cout<<" Rs. 600,000 to 900,000"<<"\n";
}
public: //access specifier
void oli()
{
cout<<"Petrol"<<"\n";
}
private:
void piston()
{
cout<<"4 piston"<<"\n";
}
private: //access specifier
void manwhomade()
{
cout<<"markus librette"<<"\n";
}
};
void main()
{
car obj;
obj.company(); // calling function
obj.model(); // calling function
obj.color(); // calling function
obj.cost(); // calling function
obj.oil(); // calling function
}

Output:

Renault
Duster
Red/brown/silver
Rs. 600,000 to 900,000
Petrol

void piston() and void manwhomade() it can not be accessed outside that class. Because it can declare in private.

Advantages of Data Abstraction :

  • We can provide security of data using Abstraction.
  • Data Abstraction avoids code dublication and increases the code reusability.
  • We don't have to write the low- level code because private element of a class can not be accessed outside that class.