Polymorphism: ============= Poly ==> Many Morphs ==> Forms class ===== ==> Blueprint ==> collection of: variables ==> to store values constructor ==> to initialize the variables in class methods ==> to perform the specific task m1() { a = 100; b = 200; c = a+b; print(c); } Note: ==== Java does not support the polymorphism to the constructor. Because, the constructor in Java can be used for initializing the class data. Ex: ==== Eating: with hand with spoon Recharge: we can do with coupon we can do without coupon Exam: Q1 to Q5 Q5 to Q1 Q3 Q2 Q4 Q1 Q5 ==> Polymorphism can be implemented in two ways: 1) Method Overloading 2) Method Overriding Ex: void m1(int x, int y) { int s = x + y; System.out.println(s); } void m1(int x, float y) { System.out.println(x+y); } void m1(float y,int x) { =============================================== void overriding(int x,int y) { System.out.println(x+y); } int overriding(int x,double y) { return x+y; } void override(int p,int q,int r) { SOP(p+q+r); } void override(int x, int y, float z) { SOP(x+y-z); } Q: Do java support operator overloading? Ans: ==== No, 100 + 200 = 300 ==> Addition "Java" + 2 ==> "Java2" ==> Concatenation + ==> Multi purpose Most Java operators: by default overloaded * 2 * 3 ==> 6 "2"* "3" - ==> subtraction __sub__() Two types polymorphism: 1) Static polymorphism/Compile Time Polymorphism 2) Dynamic Polymorphism/Run Time Polymorphism ==> If Polymorphism can be implemented with overloading technique is called as "Static Polymorphism". ==> If Polymorphism can be implemented with overriding technique is called as "Static Polymorphism". 1) Static polymorphism ====================== package Java.IO.AIT; class MobileRecharge{ // same method we have defined with two parameters only public void doRecharge(long number,double amount) { System.out.println("The Recharge has Successfull with doRecharge(number,amount)."); } // same method have defined with three parameters public void doRecharge(int number,double amount,String coupon) { System.out.println("The Recharge has Successfull with doRecharge(number,amount,coupon)."); } } public class MainClass { public static void main(String[] args) { MobileRecharge mrc = new MobileRecharge(); mrc.doRecharge(8977029779l,2099.0); mrc.doRecharge(89770297,2099.0, "AshokIT2025"); } } ==> Method Overloading can be based on: 1) Length of parameters 2) Order of parameters 3) Type of Parameters ==> while doing the method overloading: 1) method name must be same 2) operation/task also be same. 3) return type also be same.