Jan 24, 2026
## Chapter 11: OOP Basics (The Blueprint and the House)
Object-Oriented Programming (OOP) is just a way to organize your code so you don't go crazy as your project grows. I tell my students: **"A Class is the drawing of a house, and an Object is the actual house."**
### 1. Classes and Objects
**Example 1: The Student Blueprint (Basic Example)**
```java
class Student {
String name;
void study() {
System.out.println(name + " is studying.");
}
}
// Using it:
Student s1 = new Student();
s1.name = "Ravi";
```
**Example 2: The "Birth" of an Object (Common Mistake)**
```java
class Dog {
Dog() { // Constructor
System.out.println("A dog is born!");
}
void Dog() { } // ERROR! This is a method, not a constructor
}
```
*Teacher's Note:* Students often add `void` to constructors. If you add `void`, it becomes a normal method and won't run automatically when you do `new Dog()`. Constructors have **NO return type**.
### 2. Encapsulation (The Medicine Capsule)
Hide your data so no one can break it.
**Example 3: The ATM (Real-Life Analogy)**
You don't touch the money inside an ATM directly; you use the buttons.
```java
class BankAccount {
private int balance; // Hidden!
public void deposit(int amount) {
if (amount > 0) balance += amount;
}
}
```
### 3. Static vs Instance
**Example 4: The School Name (Explanation Focused)**
If 50 students go to the same school, don't give each one a separate copy of the name. Use `static`.
```java
class Student {
String name; // Unique for each
static String school = "Global School"; // Shared by all
}
```
**Example 5: The `this` Keyword (Future Hint)**
```java
this.name = name;
```
*Teacher's Note:* `this` just means "Me." We'll use it to distinguish between the class variable and the input variable.