Every technical round touches OOP. The pillars are easy to list and hard to explain โ interviews grade the explanation.
The four pillars with one running example
class Account {
#balance = 0; // ENCAPSULATION โ private state
deposit(amt) {
if (amt <= 0) throw new Error(); // controlled access
this.#balance += amt;
}
get balance() { return this.#balance; }
}
class SavingsAccount extends Account { // INHERITANCE โ reuse + extend
addInterest() { this.deposit(this.balance * 0.04); }
}- Encapsulation: bundle data + methods, hide internals. "Change balance only through deposit()"
- Abstraction: expose WHAT, hide HOW. You call
account.deposit()without knowing the ledger logic. (Follow-up trap: abstraction = hiding complexity at design level; encapsulation = hiding data at implementation level) - Inheritance: is-a relationships. SavingsAccount IS An Account
- Polymorphism: same call, different behavior โ
account.calculateInterest()works differently on Savings vs Current. Method overriding = runtime polymorphism; overloading = compile-time (Java)
The follow-ups that filter
- "Abstract class vs interface?" โ abstract: shared code + contract, single inheritance; interface: pure contract, multiple allowed
- "Composition vs inheritance?" โ prefer composition ("has-a") for flexibility; inheritance couples tightly
- "Overriding vs overloading?" โ same signature in child vs same name different params
Full practice: interview question bank.