oops · high
The Four Pillars of OOP
The four pillars of object-oriented programming in C++. Encapsulation bundles data with the methods that guard it and hides internal state (private fields + public methods preserve invariants). Abstraction exposes WHAT a type does, not HOW, through interfaces like a pure-virtual Shape::area(). Inheritance models an IS-A relationship and reuses a base's contract (Circle : Shape), specializing via overrides. Polymorphism lets one interface take many runtime forms — a single call site dispatches through the vptr/vtable to the real type, so new types slot in without changing existing code. Together they make code modular, extensible and safe.
OOP's four pillars: Encapsulation (hide state behind an interface), Abstraction (expose WHAT not HOW), Inheritance (IS-A + reuse), Polymorphism (one interface, many runtime forms via virtual dispatch). Everything else is built from these four.
The code
struct Account { // 1) ENCAPSULATION: state behind methods long cents_ = 0; // private data — invariant kept insidepublic: void deposit(long c){ cents_ += c; }};struct Shape { // 2) ABSTRACTION: expose WHAT, not HOW virtual double area() const = 0; // pure interface};struct Circle : Shape { // 3) INHERITANCE: IS-A + reuse double r; double area() const override { return 3.14159*r*r; }};void print(const Shape& s) { // 4) POLYMORPHISM: one call, many forms std::cout << s.area(); // virtual dispatch picks the real type}What this lesson walks through
- 01OOP rests on four pillars
- 02Encapsulation — hide state behind an interface
- 03Abstraction — expose WHAT, not HOW
- 04Inheritance — IS-A and code reuse
- 05Polymorphism — one interface, many runtime forms
Object-oriented programming in C++ is built on four ideas. Encapsulation bundles data with the methods that guard it and hides the state. Abstraction exposes WHAT a type does, not HOW. Inheritance models an IS-A relationship and reuses code. Polymorphism lets one interface take many runtime forms. Everything else in OOP is built from these four.
See it animated — step by step, at your own pace
Unlock the full interactive walkthrough of The Four Pillars of OOP and 100+ animated C++ interview lessons.