The Four Pillars
OOP organizes code around objects. Encapsulation, Abstraction, Inheritance and Polymorphism are its pillars.
Cheat sheet
- ▸Encapsulation: bundle data + methods, hide state (private fields + getters/setters).
- ▸Abstraction: expose what an object does, hide how (abstract classes, interfaces).
- ▸Inheritance: child class reuses parent (IS-A relationship).
- ▸Polymorphism: one interface, many forms — overloading (compile time) and overriding (runtime).
- ▸Encapsulation = data hiding; Abstraction = implementation hiding.
- ▸Prefer composition (HAS-A) over inheritance when behaviour varies.
Overloading vs Overriding
| Aspect | Overloading | Overriding |
|---|---|---|
| Binding | Compile time | Runtime |
| Where | Same class | Parent & child |
| Signature | Different params | Same signature |
| Return type | Can differ | Same or covariant |
Top 10 campus interview questions
Quick quiz
1. Method overriding is resolved at:
2. Private fields with public getters illustrate:
3. Java supports multiple inheritance through:
4. IS-A relationship represents:
5. Two methods add(int,int) and add(double,double) is: