The four pillars are Encapsulation, Abstraction, Inheritance, and Polymorphism. Together they describe how OOP organizes and reuses code.
The four pillars are Encapsulation, Abstraction, Inheritance, and Polymorphism. Together they describe how OOP organizes and reuses code.
| Pillar | Core idea |
|---|
| Encapsulation | Bundle data + behavior; hide internal state behind a controlled interface |
| Abstraction | Expose what an object does, hide how it does it |
| Inheritance | A subclass reuses and extends a parent class |
| Polymorphism | One interface, many implementations chosen at runtime |
abstract class Shape { // ABSTRACTION: "what", not "how"
abstract double area(); // each shape decides its own formula
}
class Circle extends Shape { // INHERITANCE: Circle is a Shape
private double r; // ENCAPSULATION: r is private
Circle(double r) { this.r = r; }
double area() { return Math.PI * r * r; } // POLYMORPHISM: own area()
}
class Square extends Shape {
private double s;
Square(double s) { this.s = s; }
double area() { return s * s; }
}
Shape shape = new Circle(2); // POLYMORPHISM in action:
System.out.println(shape.area()); // calls Circle.area() at runtime
These are tools, not goals. Forcing inheritance or abstraction where it isn't needed creates complexity. Reach for the pillar that fits the problem.
These four words are the shared vocabulary of OOP design — interviews and code reviews assume you know them.
Each pillar maps to a concrete benefit: encapsulation protects invariants, abstraction reduces what you must understand, inheritance and polymorphism enable reuse and extensibility.
A library of IT interview questions with detailed answers — from Junior to Senior.
Donate