# What Is OOP? Classes, Objects and the Four Pillars

Source: https://skills101.in/learn/oops/what-is-oop — Skills101 free tutorial (OOP Concepts). Updated 2026-11-09.

**Object-Oriented Programming (OOP)** is a way of organising code around **objects** — things that hold **data** and the **actions** that work on that data. Almost every company codebase in Java, Python, C# or C++ is written this way, so OOP questions appear in nearly every technical interview.

## 1. Why OOP? Procedural vs object-oriented

![Procedural code keeps data separate, so any function can change any data. OOP puts the balance and the methods that protect it together in a BankAccount object](https://skills101.in/learn-img/oops/procedural-vs-oop.svg)

In **procedural** code (like C), data and functions are separate. As programs grow, any function can change any data, and bugs become hard to trace.

In **OOP**, each object keeps its own data and exposes only safe actions. Changing one part of the program is less likely to break another.

## 2. Class and object

- A **class** is a **blueprint** (the design of a car).
- An **object** is a **real thing** made from it (your car, my car).
- An object has **state** (data, also called fields or attributes) and **behaviour** (methods).

```python
class Car:
    def __init__(self, brand, speed=0):
        self.brand = brand      # state
        self.speed = speed

    def accelerate(self, by):   # behaviour
        self.speed += by
        return f"{self.brand} now at {self.speed} km/h"

swift = Car("Swift")
nexon = Car("Nexon", 20)
print(swift.accelerate(40))
print(nexon.accelerate(40))
```

```text
Swift now at 40 km/h
Nexon now at 60 km/h
```

The same idea in Java:

```java
class Car {
    String brand;
    int speed;
    Car(String brand, int speed) { this.brand = brand; this.speed = speed; }
    String accelerate(int by) {
        speed += by;
        return brand + " now at " + speed + " km/h";
    }
}

public class Main {
    public static void main(String[] args) {
        Car swift = new Car("Swift", 0);
        System.out.println(swift.accelerate(40));
        System.out.println(swift.accelerate(15));
    }
}
```

```text
Swift now at 40 km/h
Swift now at 55 km/h
```

Each object remembers its **own** state: the two cars have different speeds.

## 3. The four pillars

![The four pillars of OOP: Encapsulation (bundle and hide), Abstraction (show what, hide how), Inheritance (reuse a parent) and Polymorphism (one name, many forms), standing on classes and objects](https://skills101.in/learn-img/oops/four-pillars.svg)

| Pillar | One line | Real-life example |
|---|---|---|
| **Encapsulation** | keep data private; allow access through methods | an ATM lets you withdraw, not open the vault |
| **Abstraction** | show what it does, hide how | you press "send" on WhatsApp, not TCP packets |
| **Inheritance** | a child class reuses a parent class | a Savings account is an Account |
| **Polymorphism** | one name, many behaviours | "pay()" works for UPI, card or cash |

The next lessons cover each pillar in detail.

## 4. Benefits of OOP

- **Reusability** — write a class once, create many objects; inherit instead of copy-paste.
- **Maintainability** — changes stay inside a class.
- **Modelling** — code mirrors real things (Student, Order, Payment), so it's easier to discuss with non-programmers.
- **Security** — encapsulation protects data from misuse.

## Common mistakes

- Saying "class and object are the same". A class is a design; an object is an instance.
- Thinking OOP is a language. It's a **style**; Java, Python, C++, C# all support it.
- Making everything a class — small scripts can be simple functions.

## Quick recap

- OOP organises code into objects with state and behaviour.
- Class = blueprint; object = instance with its own state.
- Four pillars: encapsulation, abstraction, inheritance, polymorphism.
- Benefits: reuse, easier changes, real-world modelling, safety.


Practice quiz and free certificate: https://skills101.in/learn/oops/what-is-oop