Careeroza
What is OOP
Object-Oriented Programming
So far all our code lived in main and static methods. Real programs model things from the real world (students, products, orders, accounts). Object-oriented programming (OOP) groups the data and the behaviour of such a thing together.
- A class is a blueprint or template: it says what data and actions a thing has.
- An object is one real instance made from that blueprint, with its own data.
Class: Car (blueprint) Objects (instances) +--------------------+ +-------------------+ +-------------------+ | brand, color, speed| ----> | brand = "Tata" | | brand = "Maruti" | | accelerate() | | color = "Red" | | color = "White" | | brake() | | speed = 40 | | speed = 0 | +--------------------+ +-------------------+ +-------------------+
The Four Pillars
| Pillar | Idea (one line) | Level |
|---|---|---|
| Encapsulation | hide data inside the object, expose safe methods | medium |
| Inheritance | a class reuses another class (extends) | medium |
| Polymorphism | one interface, many behaviours | medium |
| Abstraction | show what an object does, hide how | medium |
Note: This module gives you a solid first look. The medium level covers constructors, this, static vs instance, access modifiers and the four pillars in depth.