static variables, methods, blocks in JAVA-hindi-vishmy1.blogspot.com

static variables, methods, blocks, nested class in java

static variable:- when a variable declared with the static keyword, it is known as a static variable. if we created a single static variable which means we can share that variable among all objects at class level. static variables are, basically, global variables. all objects of the class share the same static variable.

static variable:- जब किसी वैरिएबल को स्टैटिक कीवर्ड के साथ घोषित किया जाता है, तो इसे स्टैटिक वेरिएबल के रूप में जाना जाता है। यदि हमने एक single static variable बनाया है जिसका अर्थ है कि हम उस variable को class level पर सभी वस्तुओं के बीच साझा कर सकते हैं। static variable, मूल रूप से,  global variables हैं। कक्षा की सभी वस्तुएँ समान स्थिर चर साझा करती हैं।

Note:- static variables are created from class-level only.

ex:- 

//static vaariable.

static int a=10;
statatic int b;

Static Method:- When a method is declared with the static keyword, it is called a static method. static methods basically belong to the class instead of the object. static methods can be called without creating the object of the class in which the method is declared. They are meant to be used without creating objects of the class. static methods can not refer to this or super keyword in any way.

स्टैटिक मेथड: - जब किसी विधि को स्टेटिक कीवर्ड के साथ घोषित किया जाता है, तो उसे स्टेटिक मेथड कहा जाता है। स्थैतिक विधियां मूल रूप से वस्तु के बजाय कक्षा से संबंधित हैं। जिस कक्षा में विधि घोषित की जाती है, उस वस्तु का निर्माण किए बिना स्थैतिक विधियों को बुलाया जा सकता है। इनका उपयोग कक्षा की वस्तुओं को बनाए बिना किया जाता है। स्थिर विधियाँ इस या सुपर कीवर्ड को किसी भी तरह से संदर्भित नहीं कर सकती हैं।
Note:- static methods are widely used in utility and helper classes

static methods can directly call the static methods.

static method can directly call to the static variable.

उपयोगिता और सहायक वर्गों में स्थिर तरीकों का व्यापक रूप से उपयोग किया जाता है।

स्थैतिक विधियाँ सीधे स्थैतिक विधियों को कॉल कर सकती हैं।

स्थैतिक विधि सीधे स्थैतिक चर को कॉल कर सकती है।

//static method.

static void m1()
{
    statement;
}

static block:- A static block is used for initializing static variables. you can declare a static block that gets executed exactly once when a class is first loaded. if a static variable requires additional, multi-statement logic while initialization, then a static block can be created.

स्टैटिक ब्लॉक: - स्टैटिक ब्लॉक का इस्तेमाल स्टैटिक वैरिएबल को इनिशियलाइज़ करने के लिए किया जाता है। आप एक स्थिर ब्लॉक की घोषणा कर सकते हैं जो एक वर्ग के पहले लोड होने पर ठीक एक बार निष्पादित हो जाता है। यदि स्थैतिक चर को आरंभीकरण करते समय अतिरिक्त, बहु-कथन तर्क की आवश्यकता होती है, तो एक स्थैतिक ब्लॉक बनाया जा सकता है।

Note:- static block and static variable are executed in the order they are presented in the program.

स्टैटिक ब्लॉक और स्टेटिक वैरिएबल को प्रोग्राम में प्रस्तुत किए गए क्रम में निष्पादित किया जाता है।

//static block

static{

 statement;


static nested class:- In java programming language we can not create a class with static keyword, but it allows us to create a class within a class. the class declared within a class is also called a nested class. the class that is declared within the class can be created with the static keyword, and that is called a static nested class. static nested class helps to keep our code more organized and readable.

स्टेटिक नेस्टेड क्लास: - जावा प्रोग्रामिंग लैंग्वेज में हम स्टैटिक कीवर्ड वाली क्लास नहीं बना सकते हैं, लेकिन यह हमें क्लास के अंदर क्लास बनाने की अनुमति देता है। किसी वर्ग के भीतर घोषित वर्ग को नेस्टेड क्लास भी कहा जाता है। वह वर्ग जिसे कक्षा के भीतर घोषित किया गया है उसे स्थैतिक कीवर्ड के साथ बनाया जा सकता है, और जिसे स्थिर नेस्टेड क्लास भी कहा जाता है। स्टेटिक नेस्टेड क्लास हमारे कोड को अधिक व्यवस्थित और पठनीय रखने में मदद करता है।

static variables, methods, blocks in JAVA-hindi-vishmy1.blogspot.com

Ex:-  Program for static keyword usage.

class test
{
    //static variable
    static int n1 = 10;
    static int n2;

   //static block
    static{
    System.out.println("static block initialized :");
    b = a+ 10;
  }
 //static method
  static void m1()
  {
       System.out.println("this is static method :");
  }
  public static void main(String args[])
   {
        System.out.println("value of a :" + a);
        System.out.println("value of b :" + b);
   }
}
   
 
Note:-  In the above program, I have not used a static nested class.

please write a comment if you find anything incorrect. this will help me to improve myself and I can provide you better information.  

                                                                                        thank you!!







Post a Comment

3 Comments

  1. It is very nice thet you have explained in hindi and english both language
    It's easy to understand

    ReplyDelete
  2. Awesome post
    Agar aapko hindi punjnabi marathi tamil bhojpuri song ya singer pasand ha to niche diye hue link par jake unke koi bhi song ya kisi bhi song ko search krke unki lyrics dekh sakte ha

    hindi song lyrics punjabi song lyrics english song lyrics new song lyrics

    ReplyDelete