OOP · Why Do We Even Need OOP?
What is OOP?
As the library grows to thousands of books, managing everything becomes difficult.
As the library grows to thousands of books, managing everything becomes difficult. Different librarians may accidentally modify the same book information, duplicate records may appear, and updating the system becomes time-consuming. A better solution is to keep each book's information together with the operations that belong to it.
For example, a Book contains its details such as title, author, and ISBN, along with the actions that can be performed on it, such as borrow(), returnBook(), and checkAvailability().
By keeping the data and its related operations together, the library system becomes easier to maintain, more organized, and simpler to expand. This idea forms the foundation of Object-Oriented Programming (OOP).
Object-Oriented Programming (OOP) is a software design approach that organizes a program using classes and objects. It combines data (attributes) and the functions (methods) that operate on that data into a single unit called an object.

OOP bundles state and the behavior that acts on it into self-contained objects.
public class Account {
private double balance; // state lives inside the object
public void deposit(double amount) { balance += amount; } // behavior
public void withdraw(double amount) {
if (amount <= balance) balance -= amount;
}
public double getBalance() { return balance; }
public static void main(String[] args) {
Account acc = new Account(); // an object owns its own data
acc.deposit(100);
acc.withdraw(30);
System.out.println(acc.getBalance()); // 70.0
}
}