What is a method in JAVA in hindi ?-vishmy1.blogspot.com

Methods in JAVA



A Method is a block of organizes reusable code that is used to perform a single related function.

एक विधि(Method) पुन: प्रयोज्य(reusable) कोड को व्यवस्थित(organizes) करने का एक ब्लॉक है जो किसी एकल संबंधित फ़ंक्शन(single related function) को करने के लिए उपयोग किया जाता है।

Methods provide better modularity for your application and a high degree of code reusing.

विधियाँ आपके आवेदन के लिए बेहतर मॉड्युलैरिटी प्रदान करती हैं और उच्च श्रेणी कोड का पुन: उपयोग करती हैं।

The method helps to break our program into smaller and modular code blocks by using method a bigger program that can be made more organized and manageable.


विधि हमारे कार्यक्रम को छोटे और मॉड्यूलर कोड ब्लॉक में तोड़ने में मदद करती है विधि का उपयोग करके एक बड़े कार्यक्रम को अधिक संगठित और प्रबंधनीय बनाया जा सकता है।

The best advantage of the method is that it avoids repetition and makes code reusable, when you define a method you need to specify the name and the sequence of the method.  

विधि का सबसे अच्छा लाभ यह है कि यह दोहराव से बचा जाता है और कोड को पुन: प्रयोज्य बनाता है, जब आप एक विधि को परिभाषित करते हैं जिसे आपको नाम और विधि के अनुक्रम को निर्दिष्ट करने की आवश्यकता होती है।

Syntax:-

access_modifier return_type method_name(parameter)
{
                       statement;
}



accessing a method :- 

After an object is created, its data can be access and its method is invoked (call) using the dot(.) operator, also known as object member access operator.  

किसी ऑब्जेक्ट के बनने के बाद, उसका डेटा एक्सेस किया जा सकता है और डॉट (.) ऑपरेटर का उपयोग करके इसकी विधि को कॉल (कॉल) किया जाता है, जिसे ऑब्जेक्ट सदस्य एक्सेस ऑपरेटर के रूप में भी जाना जाता है।

syntax:-

object_name.variable_name
object_name.method-name( );

ex:- creating a method.

class test
{
         public string name;
         public int age ;
         public void show ( )
        {
               System.out.println("show method");
         }
         public static void main ( String args [ ] )
          {
                 test t1= new test();
                 t1.name = "vishmyblog";
                 t1.age = 21;
                 System.out.println(name);
                 System.out.println(age);
                 t1.show();
           }
}

Returning a method :-

Method returns a value, the return statement terminates the execution of the method in which it appears can also return the value of the optional expression, if the method of the type void The return statement is omitted. the type of data return by a method must be comfortable with the return type specified the method.

विधि(method) एक मान(value) लौटाता(return) है, रिटर्न स्टेटमेंट उस पद्धति(method) के निष्पादन(execution) को समाप्त(terminates) करता है जिसमें यह प्रकट होता है कि वैकल्पिक(optional) अभिव्यक्ति(expression) का मान भी वापस आ सकता है, यदि प्रकार की विधि शून्य(void) कथन लौटा दी जाती है। किसी विधि द्वारा डेटा वापसी का प्रकार विधि निर्दिष्ट रिटर्न प्रकार के साथ सहज होना चाहिए।


Syntax :-

return expression;

ex :- 

class test 
{
    public int addition(int a, int b)
    {
          int c;
          int c=a+b;
          return c;
    }
    public static void main(String args[])
    {
             test t1 = new test();
             int d;
             d = e2.addition(10, 20);
             System.out.println(d);
    }

}



   

Post a Comment

0 Comments