4 Replies Latest reply: Apr 11, 2007 4:42 AM by 800322 RSS

    static

    807606
      A static variable is initialized when a class is loaded, what it means
        • 1. Re: static
          791266
          That the value is set when the class is loaded.
          • 2. Re: static
            807606
            class is loaded ---------from where to where it is loaded
            • 3. Re: static
              807606
              Hey here is a great help
              A static variable is intilized when the class is loded. Which means that
              the static variable will have the same value regardless of the number of
              objects we create from that class. And the value of that static variable is the same in all objects of that class.
              Example let say there is a static variable x in class animal
              lets say we create an object called cat from the class animal and also an object dog.
              the value of the vairable x is the same in both cat and dog always.
              if we make
              cat.x=9
              then the x in dog will also be 9.
              Hence, static variables can be used to share a common information
              between objects of the same class. For example the number of legs is
              common to both cats and dogs
              • 4. Re: static
                800322
                the value of the vairable x is the same in both cat
                and dog always.
                if we make
                cat.x=9
                dog will also be 9.
                And the whole point is: static variables are not related to class's objects, and they are not supposed to be accessed through an object reference.