Skills101

OOP Concepts · Lesson 1 of 8 · Updated ·

What Is OOP? Classes, Objects and the Four Pillars

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

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).
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))
Swift now at 40 km/h
Nexon now at 60 km/h

The same idea in 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));
    }
}
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

PillarOne lineReal-life example
Encapsulationkeep data private; allow access through methodsan ATM lets you withdraw, not open the vault
Abstractionshow what it does, hide howyou press "send" on WhatsApp, not TCP packets
Inheritancea child class reuses a parent classa Savings account is an Account
Polymorphismone 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 what you learned

📝 Quiz: What Is OOP5 questions · instant answers & explanations · +10 XP · counts towards your free certificateTake the quiz →