Method Overloading

Java Method Overloading In Hindi

Java

Java Method Overloading In Hindi – Is Post Me Method Overloading Ke Bare Me Read Karne Wale Hai And Method Overloading in Java In Hindi Ke Examples Ko Bhi Dekhne Wale Hai|

Also Read – What is Java in Hindi

Java Method Overloading In Hindi

JAVA Me Jab Do Ya Do Se Jyada Methods/ Functions Ka Naam Ek Jaisa Ho Lekin Unke Parameters Me Difference Ho ( different number of parameters, different types of parameters, or both) Toh Unn Methods Ko Hum Overloaded Method Kehte Hain Aur Is Prikriya Ko Method Overloading.

Neeche Diye Gye Example Se Hum Achhi Trah Se Seekhenge Ki Method Overloading Kaise Kiya Jata Hai.

Example:

void func() { ... }
void func(int a) { ... }
float func(double a) { ... }
float func(int a, float b) { ... }

Jaisa Ki Humne Example Me Dekha Ki Ek Hi Naam Se Chaar Trah Ke Methods/ Functions Define Kiye Hue Hain.

  • Line1 Me Jo Method Hai, Uska Na Toh Koi Return Type Hai Aur Na Hi Koi Parameter Hain.
  • Line2 Me Jo Method Hai, Uska Return Type Line1 Ke Method Jaisa Hi Hai Lekin Uske Paas Integer Type Ka Ek Parameter Hai.
  • Line3 Me Jo Method Hai, Uska Return Type Float Hai Aur Parameter Bhi Double Type Ka Hai.
  • Line4 Me Jo Method Hai, Uska Return Type Line3 Ke Method Jaisa Hi Hai Lekin Uske Do Parameters Hain.

NOTE: Zaroori Nahi Ki Methods Ka Return Type Ek Jaisa Hai Ya Alag Hai Lekin Zaroori Yha Hai Ki Unke Number Aur Type Of Parameters Different Hain.

Why Method Overloading in Hindi?

Maan Lijiye Ki Hume Addition Perform Karna Hai Lekin Hum Kitne Bhi Aur Kisi Bhi Type Ke Arguments Pass Kar Sakta Hai.

Jaise ki,

add2integers(12 , 13) ———-> 2 integer parameter

add2float(43.1 , 56.3) ———-> 2 float arguments

add3integers(34 , 67 , 88) ———-> 3 integer arguments

Iss Case Me 3 Alag-Alag Method Ki Bajaye Hum Ek Hi Naam Se 3 Method Define Kar Sakte Hain, Bus Hume Unke Parameters Apne Hisab Se Different Rakhne Hain. 

Also Read – Java Arrays

How to perform Method Overloading in JAVA?

JAVA Me Method Overloading Ko Kayi Tareeke Se Perform Kiya Ja Sakta Hai, Jo Ki Neeche Examples Ke Saath Samjhae Gye Hain:

1. Overloading by changing the number of arguments

class MethodOverloading {
    private static void display(int a){
        System.out.println("Arguments: " + a);
    }

    private static void display(int a, int b){
        System.out.println("Arguments: " + a + " and " + b);
    }

    public static void main(String[] args) {
        display(1);
        display(1, 4);
    }
}

Output:

Arguments: 1
Arguments: 1 and 4

2. By changing the datatype of parameters

class MethodOverloading {

    // this method accepts int
    private static void display(int a){
        System.out.println("Got Integer data.");
    }

    // this method  accepts String object
    private static void display(String a){
        System.out.println("Got String object.");
    }

    public static void main(String[] args) {
        display(1);
        display("Hello");
    }
}

Output:

Got Integer data.
Got String object.

Upar Diye Gye Example Me Hunme Dekha Ki Do display( ) Method Define Kiye Hue Hain Lekin Dono Me Ek Hi Argument Hai, Methods Ko Overload Kiya Hai Unke Data Type Ko Different Rakh Kar, Ek Hai int Aur Doosra Hai String Object.


NOTE: JAVA Me Method Overloading Ki Trah Hi Hum Constructors Ko Overload Kar Sakte Hain.

Also Read – Java Constructor Overloading


Important Points

  • Ek Class Me Do Ya Do Se Adhik Methods Ka Naam Same Rakha Ja Sakta Hai Lekin Who Jo Parameters Accept Krenge, Who Different Hone Chahiye. JAVA Ke Iss Feature Ko Method Overloading Kaha Jata Hai.
  • Method Overloading Ko Hum Do Tareeke Se Achieve Kar Sakte Hain:
    • Number Of Arguments Ko Alag-Alag Rakh Kar
    • Aur Arguments Ke Datatype Ko Alag Rakh Kar
  • Method Overloading Ko Akele Return Type Ko Alag Rakh Ke Achieve Nahi Kiya Ja Sakta Hai.

Dosto mujhe ummed hai ki aap Methods Overloading in Java in Hindi  ko acchi tarah se samanj gye honge agar aap ko ye post acchi lage to mere is website ko jarur follow kre |

Leave a Reply

Your email address will not be published. Required fields are marked *