Programming in Java
Unit 8: Inheritance & Polymorphism
Master class hierarchies, method overriding, dynamic dispatch, and build real-world OOP systems that mirror India's top tech products.
⏱️ 7 hrs theory + 5 hrs lab | 💰 ₹10K–₹30K/month | 📝 30 MCQs (Bloom's Mapped)
💼 Jobs this unlocks: Java Developer (₹5–8 LPA) | Android Developer (₹6–10 LPA) | Software Engineer (₹8–15 LPA)
Opening Hook — The Code Behind Every UPI Payment
🏢 How Paytm Handles Crores of Payments with One Class Hierarchy
Every time you pay ₹50 for chai using Paytm, a class hierarchy fires up behind the scenes. At the top sits an abstract class PaymentMethod with a method processPayment(double amount). Below it: UPIPayment, NetBankingPayment, CardPayment, and WalletPayment — each extends PaymentMethod and overrides processPayment() with its own logic.
UPI routes through NPCI. NetBanking talks to the bank's IMPS gateway. Cards hit Visa/Mastercard APIs. Wallets debit the internal ledger. One parent. Four children. Four different behaviours. One method name. That's polymorphism.
Paytm processes 1.5 billion+ transactions monthly. Without inheritance and polymorphism, they'd need separate, duplicated codebases for each payment type — unmaintainable chaos. Instead, a single line paymentMethod.processPayment(amount) handles everything through dynamic method dispatch.
Every payment hierarchy you see in Indian fintech is Java inheritance in action.
Learning Outcomes — Bloom's Taxonomy Mapped
| Bloom's Level | Learning Outcome |
|---|---|
| 🔵 Remember | Define inheritance, list the types of inheritance supported in Java, and recall the syntax of the extends keyword |
| 🔵 Remember | State the 5 rules of method overriding and identify the 3 uses of the super keyword |
| 🔵 Understand | Explain why Java doesn't support multiple inheritance with classes (diamond problem) and how interfaces solve it |
| 🔵 Understand | Differentiate between compile-time polymorphism (overloading) and runtime polymorphism (overriding) with examples |
| 🟢 Apply | Implement a Shape class hierarchy with Circle, Rectangle, and Triangle using method overriding to calculate area |
| 🟢 Apply | Build a BankAccount hierarchy with SavingsAccount and CurrentAccount using super to invoke parent constructors |
| 🟢 Analyze | Trace the output of programs involving dynamic method dispatch and predict which overridden method executes at runtime |
| 🟢 Analyze | Compare access modifier rules in method overriding and identify compilation errors in given code |
| 🟠 Evaluate | Assess whether a given class design violates the Liskov Substitution Principle and suggest corrections |
| 🟠 Evaluate | Justify when to use final on a class vs. method vs. variable in a real-world banking application |
| 🟠 Create | Design a complete Payment Gateway system using abstract classes, inheritance, and polymorphic method dispatch |
| 🟠 Create | Create a Swing GUI application by extending JFrame, overriding paint(), and adding custom event handlers |