DEV Community

Cover image for Abstraction in C++ - Explained in Simple Words
Aliza Kanwal
Aliza Kanwal

Posted on

Abstraction in C++ - Explained in Simple Words

Abstraction means showing only the important things and hiding the complex details.

Think of a car. When you drive a car, you only see steering, brake, and accelerator. You don't see how the engine works inside. You don't need to know it. You just drive. This is Abstraction!

In C++, we use Abstraction to make our code simple to use.

Let's see a simple example:


cpp
#include <iostream>
using namespace std;

class Car {
public:
    void start() {
        cout << "Car Started!" << endl;
        startEngine();
    }

private:
    void startEngine() {
        cout << "Engine is working inside..." << endl;
    }
};

int main() {
    Car myCar;
    myCar.start();
    return 0;
}
Output:
Car Started!
Engine is working inside...
Enter fullscreen mode Exit fullscreen mode

Top comments (0)