0–5 min
Real Hook
5–20 min
Core Concept
20–40 min
Live Coding
40–55 min
You Code It
55–60 min
Cheat Sheet
🔥 Real-World Hook (0–5 min)
Why does your phone update Instagram without reinstalling the whole OS? Why can a Toyota mechanic understand a BMW engine?
Object-Oriented Design. Everything is built from reusable blueprints (classes). Change one blueprint — all objects update. This is how Netflix, Uber, and Amazon build software that lasts decades.
🌍 The 4 Pillars (5–20 min)
💡 Analogies
Encapsulation — A capsule hides the chemical inside. You swallow it (call the method), not mix chemicals yourself.
Inheritance — A Manager IS an Employee. Child class gets everything from parent — no duplication.
Polymorphism — "Open" means different things: open a door, open a file. Same method name, different behaviour.
Abstraction — You drive a car without knowing the engine. Abstract class hides complexity.
💻 Live Coding — Employee Hierarchy (20–40 min)
public class Employee {
protected String name;
protected double salary;
public Employee(String name, double salary) {
this.name = name; this.salary = salary;
}
public void work() {
System.out.println(name + " is working");
}
}
public class Manager extends Employee {
private int teamSize;
public Manager(String name, double salary, int teamSize) {
super(name, salary);
this.teamSize = teamSize;
}
@Override
public void work() { // Polymorphism
System.out.println(name + " is managing a team of " + teamSize);
}
}
// Usage
Employee emp = new Employee("Priya", 50000);
Manager mgr = new Manager("Ravi", 90000, 8);
emp.work(); // "Priya is working"
mgr.work(); // "Ravi is managing a team of 8"
🔗 Interface — A Contract Every Class Must Honour
interface Payable {
double calculatePay();
}
class FullTimeEmployee implements Payable {
public double calculatePay() { return 50000; }
}
class Contractor implements Payable {
private int hours;
public double calculatePay() { return hours * 500; }
}
🎯 You Code It (40–55 min)
- Create a
BankAccount class: fields accountNo, balance; methods deposit(), withdraw(), getBalance()
- Create
SavingsAccount extends BankAccount — override withdraw() to prevent balance going below ₹500
- Create
LoanAccount extends BankAccount — add field interestRate, method calculateInterest(int months)
- In
main(): deposit ₹10,000 then try withdrawing ₹9,800 from SavingsAccount
- Goal: SavingsAccount prints "Cannot withdraw — minimum balance required"
📄 Day 4 Cheat Sheet — OOP
Class & Object
| class Car { } | Blueprint |
| Car c = new Car() | Create object |
| private int speed | Hidden field |
| public int getSpeed() | Getter |
| this.speed = speed | Own field |
Inheritance
| class Dog extends Animal | Inherit |
| super(name) | Call parent constructor |
| super.speak() | Call parent method |
| @Override | Replace parent method |
| instanceof | Check type |
Interface
| interface Flyable { } | Define contract |
| class Bird implements Flyable | Implement |
| default void method() | Optional override |
| implements A, B | Multiple OK |
| extends only ONE class | Single inheritance |
Access Modifiers
| public | Anyone can access |
| private | Only this class |
| protected | This + subclasses |
| abstract | Must be subclassed |
| final | Cannot override |
| static | Belongs to class |