Banking System Polymorphism

This program models polymorphism in a banking system.

Problem Statement

Write a Java program where Account is superclass and SavingsAccount and CurrentAccount override calculateInterest().

Source Code

1 class Account { void calculateInterest(){ System.out.println("Eduinq Generic Interest"); } }
2 class SavingsAccount extends Account { void calculateInterest(){ System.out.println("Eduinq Savings Interest Calculated"); } }
3 class CurrentAccount extends Account { void calculateInterest(){ System.out.println("Eduinq Current Account Interest Calculated"); } }
4 public class BankingPolymorphism {
5 public static void main(String[] args) {
6 System.out.println("Eduinq Banking Polymorphism");
7 Account a1=new SavingsAccount();
8 Account a2=new CurrentAccount();
9 a1.calculateInterest();
10 a2.calculateInterest();
11 }
12 }

Program Output

					Eduinq Banking Polymorphism
Eduinq Savings Interest Calculated
Eduinq Current Account Interest Calculated
				

Explanation

Account defines a generic method for interest calculation. - Subclasses override the method to provide specific logic for savings and current accounts. - Polymorphism ensures the correct method executes depending on the object type, even when referenced by the superclass. - This models real world banking systems where different account types share a common interface but require specialized behavior, ensuring scalability and maintainability in enterprise applications. Conclusion: Shows real world polymorphism in banking system.

Quick Links to Explore