Features of Object-Oriented Programming
1. OOP in One Line (beginner)
OOP = build software as objects (data + methods together, like real things). Account object holds balance + withdraw() — data locked inside, accessed via methods only!
2. Four Pillars (exam MUST — with code!)
class Account { // 1. ENCAPSULATION: lock data!
private double balance; // private (no direct touch!)
public void deposit(double x) { if (x > 0) balance += x; } // guard!
public double getBalance() { return balance; }
}
class Savings extends Account { // 2. INHERITANCE: reuse!
double interest() { return getBalance() * 0.05; } // parent method reused!
}
| Pillar | Meaning | Keywords |
|---|---|---|
| Encapsulation | hide data, expose methods | private + getters/setters |
| Inheritance | child reuses parent | extends |
| Polymorphism | same call, different behaviour | overloading/overriding |
| Abstraction | show what, hide how | abstract, interface |
3. Polymorphism Taste (full in Module 3!)
Account a = new Savings(); // parent ref, child object!
a.deposit(100); // runs child version if overridden (dynamic!)
4. OOP vs POP (one line for exams)
POP = functions + open globals (C). OOP = objects + locked data + reuse (Java).
5. Exam Points
- Four pillars + code + keywords — 7-10 marks, #1 OOP question.
- Encapsulation example (
private+ guard) — 5 marks, most-asked pillar.