Object-Oriented Programming Fundamentals

Lesson 0002 — 20 min read

OOP is a programming paradigm based on objects — instances of classes — bundling data (fields) and behavior (methods) together.

Class vs Object

A class is a blueprint. An object is an instance built from that blueprint, with its own state.

// Class: the blueprint
class BankAccount {
    String owner;
    double balance;

    void deposit(double amount) {
        balance += amount;
    }
}

// Objects: instances with their own state
BankAccount rajsAccount = new BankAccount();
BankAccount johnsAccount = new BankAccount();

Procedural vs OOP

Aspect Procedural OOP
Approach Step-by-step sequence of actions Model entities as objects with data + behavior
Data Handling Globally accessible, prone to accidental modification Encapsulated within objects, access via methods
Reusability Limited (function-level reuse only) High (inheritance, polymorphism)
Scalability Harder — new features touch many functions Easier — new classes, minimal ripple effect
Modularity Functions, but logic/data separation is weak Classes and objects, clear separation
Real-World Modeling Actions-focused, unintuitive for entities Mirrors real-world entities and relationships

Why OOP Wins for Large Systems

Real-Life Analogy: Bank

OOP Concept Bank Example
Class Account, Customer, Transaction
Object Raj's Account, John's Transaction
Attributes customer name, balance, account number
Methods deposit(), withdraw(), transfer()

Which approach does this code follow?

String name = "Raj";
int balance = 5000;

void deposit(int amt) {
    balance += amt;
}

void printName() {
    System.out.println(name);
}

Which is NOT a benefit of OOP over procedural programming?

Notes

OOP :-

Object-oriented ⇒ paradigm based on objects (data + behavior)

Class ⇒ blueprint ; Object ⇒ instance of class (eg Raj's Account)

OOP vs Procedural :-

a) Approach ⇒ sequential vs entity-modeled

b) Data ⇒ global (unsafe) vs encapsulated (safe)

c) Reuse ⇒ function-level vs inheritance + polymorphism

d) Scale ⇒ brittle vs extensible via new classes

e) Modularity ⇒ weak separation vs class boundaries

f) Modeling ⇒ actions-first vs entities-first

Why OOP for large systems :-

Goal ⇒ manage complexity at scale

a) Modularity ⇒ break into classes (eg Account, Customer, Transaction)

b) Reusability ⇒ parent — child (eg Vehicle — Car, Bike)

c) Scalability ⇒ add features without breaking existing code

d) Security ⇒ private fields ; controlled access via methods

Bank analogy :-

Class ⇒ blueprints (Account, Transaction)

Object ⇒ specific instances (Raj's Account)

Attributes ⇒ name, balance, account number

Methods ⇒ deposit(), withdraw(), transfer()

Primary source: Oracle Java Tutorials — OOP Concepts. Ask me anything that's unclear.

← Prev: Java Basics Next: Class & Object →

Questions? Ask your agent — you can follow up on any concept, quiz answer, or how this applies to a specific coding problem. Review the Java glossary or syntax quick reference for a compressed overview.