Method Parameters in Java

Java Method Parameters In Hindi

Java

Java Method Parameters In Hindi – Parameters in Hind in Java – Java me method/ function ko define krte time jo list of variables hum dete hain use parameter kehte hain.

Jaisa ki last topic me humne discuss kiya ki methodName ke baad parenthesis( ) ke Under hum list of variables dete hain unke proper datatypes ke Saath, unko parameters kehte hain.

Also Read – What is Java in Hindi

Java Method Parameters In Hindi

JAVA Method Parameters – JAVA me methods ko define krte time hume kuch information methods ko pass krni hoti hai, jispe woh particular method perform krta hai or un values ko update krta hai.

Parameters puri tarah se optional hote hain, hum bina parameters ke bhi methods ko define kar sakte hain, aur apni requirements ke hisab se kitne bhi parameters ko specify kr sakte hain bass hume unko commas (,) ke saath separate krna hota hai.

JAVA Method Arguments – JAVA me Kisi bhi method/ function ko ek bar define kiya jata hai with method body. lekin hum apni requirements ke hisab se kabhi bhi or kitni bhi bar uss method ko call/ access kar sakte hain. Method ko call aur access karte time jo values hum usme pass krte hain, unhe arguments kha jata hai.

Method defination ke time jitne aur jis type ke parameters diye jate hain, toh call/ access krte time utne aur usi type ke arguments hume pass krne hote hain.

Aaiye ab ek example ke saath hum seekhenge ki parameters kya hain, method ke kis part me diye jaaye hain aur parameter aur arguments me basic difference kya hai.

Neeche diye gye example me myMethod naam se ek method define kiya gya hai aur String type se ek fname naam ka parameter pass kiya gya hai. Lekin jab hum iss method ko call ya access krenge toh hume String type ka hi ek argument pass krna hoga.

Also Read – Java Methods

Program control jab called method ke paas aaega tab  passed argument iss parameter me copy ho jaega aur hume humara output monitor screen pe mil jaega.

Example:

public class MyClass {
  static void myMethod(String fname) {
    System.out.println(fname + " Language ");
  }
  
  public static void main(String[] args) {
    myMethod("Python");
    myMethod("C++");
    myMethod("Java");
  }
}

Output:

Python Language
C++ Language
Java Langauge

Note: Jab parameter method ko pass kiya jaega tab who argument hoga. Toh upar diye gye example se clear hota hai ki: fname ek parameter hai, aur Python, C++ aur Java arguments hain.

Java Multiple Parameters In Hindi

Jaisa ki humne upar padha, ek method me parameters optional hote hain. Bina parameters ke bhi methods ko define kiya ja sakta hai aur hum apni requirements ke according kitne bhi parameters de sakte hain.

Neeche diye gye example me humne ek multiple parameters ke saath method redefine kiya hai:

Also Read – Java Arrays

Example:

public class MyClass {
  static void myMethod(String fname, int age) {
    System.out.println(fname + " is " + age);
  }
  
 public static void main(String[] args) { 
   myMethod("Ajay", 5);
   myMethod("Rohan", 8);
   myMethod("Amit", 31);
 }
}

  Output:

Ajay is 5
Rohan is 8
Amit is 31  

Note: Hume methods ko call aur access krte time ye baat zroor dhyan me rkhni hai ki multiple parameters ke case me calling method me paas kiye gye arguments ka number, datatype aur order called method ke parameters se match hona chahiye wrna hum method ko execute nahi kr paenge.

Java Return Values in Hindi

Jab hum JAVA me koi pre-defined ya user-defined method use krte hain toh, woh methods do treeke ke ho skte hai:

  • Jab method me koi returning value ho (return type as String, char, int, float,etc.)
  • Jab method koi value return na kre (return type as void)

Agar humne koi na koi return type rkha hai toh method ki body me return statement dena zroori hota hai. Upar diye gye dono examples me return type void rkha gya tha, ab hum ek example disscuss krte hai jha hum function se koi value return kraenge.

Neeche diye gye example me method ko argument 3 pass krke call kiya gya hai jo called function ko invoke krta hai aur 5 + 3 hume return krta hai.

Example

public class MyClass {
  static int myMethod(int x) {
    return 5 + x;
  }
  public static void main(String[] args) {
    System.out.println(myMethod(3));
  }
}

Outputs:

8

Neeche diye gye example me humne multiple parameters istemal kiye hain, method ko arguments bhi is baar 5, 3 pass kiye hain jo called function ko invoke krta hai aur 5 + 3 hume return krta hai.

Example

public class MyClass {
  static int myMethod(int x , int y) {
    return x + y;
  }
  public static void main(String[] args) {
    System.out.println(myMethod(5,3));
  }
}

Outputs:

8 

Also Read This Post:

Dosto mujhe ummed hai ki aap Methods 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 *