Object-Oriented Programming organises software around objects — bundles of data (attributes) and behaviour (methods) — rather than around functions and logic alone. A class is the blueprint; an object is an instance of it. The paradigm rests on four pillars that every interviewer will ask you to name and explain.
Class vs object
A class is a template defining attributes and methods; an object is a concrete instance with its own data. 'Car' is a class; your specific red car is an object. You can create many objects from one class.
The four pillars
| Pillar | Meaning |
|---|---|
| Encapsulation | bundle data + methods, hide internal state behind an interface |
| Abstraction | expose what an object does, hide how it does it |
| Inheritance | a class derives attributes/methods from a parent class |
| Polymorphism | one interface, many forms (same call, different behaviour) |
⚡ The edge
- Memorise the four pillars as A-PIE: Abstraction, Polymorphism, Inheritance, Encapsulation — then give a one-line example of each.
- Encapsulation vs abstraction is the trap pair: encapsulation hides data (private fields + getters/setters); abstraction hides complexity/implementation (you call drive(), not the engine internals).
Worked example
'What are the four pillars of OOP?'
- Name them: encapsulation, abstraction, inheritance, polymorphism.
- Give a one-liner each: encapsulation bundles and hides data; abstraction hides implementation; inheritance reuses a parent's members; polymorphism lets one interface take many forms.
- Anchor with an example: a Shape base class with area(), overridden by Circle and Square (polymorphism + inheritance).
Answer: Encapsulation, abstraction, inheritance, polymorphism — each with a one-line definition and example.
Worked example
'What is the difference between a class and an object?'
- A class is a blueprint that defines structure and behaviour but holds no data by itself.
- An object is an instance of that class, occupying memory and holding actual values.
- Analogy: the class is the architectural plan; each house built from it is an object.
Answer: A class is the blueprint; an object is a concrete instance created from it.
⚠ Watch out
- Don't confuse encapsulation (hiding data behind an interface) with abstraction (hiding implementation complexity).
- A class doesn't consume object memory until you instantiate it.
- OOP's benefits — reusability, maintainability, modelling real entities — are worth stating when asked 'why OOP'.