What are the four pillars of object-oriented programming?

C# OOP Basic Fresher1–2 Yrs Conceptual 1 min read

Quick Answer

Encapsulation — bundle data with the methods that operate on it and hide the internal state behind a controlled interface. Abstraction — expose only what a caller needs, hide how it works. Inheritance — a type reuses and extends another type (“is-a”). Polymorphism — one interface, many implementations; the right method is chosen at run time.

Encapsulation is keeping data and the code that changes it together, and hiding the internal state so it can only change through methods that keep it valid. Abstraction is showing the caller a simple contract and hiding the complexity behind it — an interface, basically. Inheritance is one class building on another for an “is-a” relationship, though I try to prefer composition. And polymorphism is one interface with many implementations, where the runtime picks the right method for the actual object. Those four are what people mean by OOP.

  • Encapsulation — private fields, public properties/methods, invariants enforced in one place. Account.Withdraw(amount) checks the balance; callers can't set _balance directly.
  • Abstraction — IEmailSender.Send(...): callers don't know or care whether it's SMTP or a queue. Achieved with interfaces and abstract classes. (Abstraction and encapsulation overlap — abstraction is about the design view, encapsulation about the mechanism.)
  • Inheritance — SavingsAccount : Account reuses Account's behaviour and adds interest. Use sparingly; favour composition when the relationship isn't a true “is-a”.
  • Polymorphism — Account acc = new SavingsAccount(); acc.CalculateInterest(); runs the savings version. Also covers overloading (compile-time) and generics (parametric).