What is Polymorphism?

 
Polymorphism means "many forms."

In Java, it allows a single interface or method to act differently based on the object it is working on.

Real-Life Example: Payment System : 

Imagine you're building an online shopping app. At checkout, a customer can choose from different payment methods:

💳 Credit Card

🏦 Bank Transfer

📱 UPI

💼 Wallet

In the checkout system, we only call the method:

payment.pay(amount);

Based on the object assigned to the payment reference, the correct implementation is executed:

let's see step by step

Step 1: Create a Common Interface

We define a Payment interface with a method pay(double amount). Every payment method will implement this interface.