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)

Section A

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.

🇮🇳 Paytm🇮🇳 PhonePe🇮🇳 Google Pay🇮🇳 CRED🇮🇳 Razorpay
Java runs on 3+ billion devices worldwide — from Android phones in Tier-3 Indian cities to IRCTC's backend servers, SBI's core banking, and Aadhaar authentication. Every major Indian bank's backend is built with Java class hierarchies using inheritance and polymorphism. Learning this unit literally teaches you the architecture behind India's digital economy.
Section B

Learning Outcomes — Bloom's Taxonomy Mapped

Bloom's LevelLearning Outcome
🔵 RememberDefine inheritance, list the types of inheritance supported in Java, and recall the syntax of the extends keyword
🔵 RememberState the 5 rules of method overriding and identify the 3 uses of the super keyword
🔵 UnderstandExplain why Java doesn't support multiple inheritance with classes (diamond problem) and how interfaces solve it
🔵 UnderstandDifferentiate between compile-time polymorphism (overloading) and runtime polymorphism (overriding) with examples
🟢 ApplyImplement a Shape class hierarchy with Circle, Rectangle, and Triangle using method overriding to calculate area
🟢 ApplyBuild a BankAccount hierarchy with SavingsAccount and CurrentAccount using super to invoke parent constructors
🟢 AnalyzeTrace the output of programs involving dynamic method dispatch and predict which overridden method executes at runtime
🟢 AnalyzeCompare access modifier rules in method overriding and identify compilation errors in given code
🟠 EvaluateAssess whether a given class design violates the Liskov Substitution Principle and suggest corrections
🟠 EvaluateJustify when to use final on a class vs. method vs. variable in a real-world banking application
🟠 CreateDesign a complete Payment Gateway system using abstract classes, inheritance, and polymorphic method dispatch
🟠 CreateCreate a Swing GUI application by extending JFrame, overriding paint(), and adding custom event handlers