Video in progress
What are the four pillars OOP rests on, and what does each one mean in a sentence?
Encapsulation (hiding data and managing it only through methods), inheritance (extending an existing class), polymorphism (one call, different behavior) and abstraction (hiding unneeded detail and showing only what matters).
📖 Answer
In an interview, just naming the list is not enough. Give a small example for each:
| Principle | In one sentence | How it looks in Java |
|---|---|---|
| Encapsulation | An object guards its own state | a private field + a method with validation |
| Inheritance | Shared code is written in the parent class | class Admin extends User |
| Polymorphism | The caller doesn't know the exact type | area() on items of a List<Shape> |
| Abstraction | Show the user only the "what" | interface PaymentGateway |
For example, in a BankAccount class the balance field is private and can only be changed through deposit() and withdraw(): that is encapsulation. The PaymentGateway interface declares pay(), and the caller doesn't care whether Click or Payme is behind it: that is abstraction, and picking the right implementation at runtime is polymorphism.
Interviewers often hear abstraction and encapsulation mixed up. A simple distinction: abstraction is about what to show, encapsulation is about how to hide it.
Sign up to mark studied questions and save your progress.