13 Replies Latest reply: Mar 19, 2007 11:49 PM by 807599 RSS

    What is static?

    807599
      I can see that methods and variables can be static and i can't understand how this works.
        • 1. Re: What is static?
          807599
          http://mindprod.com/jgloss/static.html
          • 2. Re: What is static?
            807599
            In short, static means the variable or method isn't part of the instance but part of the class. So when you create an object, this variable or method isn't part of that object. To use a static variable or method, you need to place the name of the class in front of it, like this:
            Math.abs(3);
            The abs method is static and it's in the Math class so you can call it like that. Static variables work in the same way. You should look up some documentation for a full explanation of the static keyword.
            • 3. Re: What is static?
              807599
              I know the definition between instances and class i don't know if my comprehension to this matter is correct. Can you please elaborate the difference of the two. Thanks
              • 4. Re: What is static?
                800387
                Static is when you have wool socks on and you drag your feet across a room. Fun stuff indeed!

                In Java at least, static means that the variable is stored at the class level. Instance variables are stored, well, at the instance (or object) level. A given class definition exists only once per JVM. Any number of instances may exist. So, any static variables are 'seen' or 'shared' or 'visible' to all instances of that class.

                - Saish
                • 5. Re: What is static?
                  807599
                  Well, at least i got the hunch of it. Guess i have to figure this out for myself. Thank to all!!!
                  • 6. Re: What is static?
                    807599
                    Well, at least i got the hunch of it. Guess i have to
                    figure this out for myself. Thank to all!!!
                    So did this not help at all?
                    http://mindprod.com/jgloss/static.html
                    and which part of this was unclear?
                    In short, static means the variable or method isn't part of the instance
                    but part of the class. So when you create an object, this variable or
                    method isn't part of that object. To use a static variable or method, you
                    need to place the name of the class in front of it, like this:
                    Math.abs(3);

                    The abs method is static and it's in the Math class so you can call it
                    like that. Static variables work in the same way. You should look up
                    some documentation for a full explanation of the static keyword.
                    • 7. Re: What is static?
                      807599
                      i don't know if my comprehension to this matter is correct. Can you please elaborate the difference of the two.
                      You first. Elaborate on your comprehension.
                      • 8. Re: What is static?
                        807599
                        Well, at least i got the hunch of it. Guess i have
                        to
                        figure this out for myself. Thank to all!!!
                        So did this not help at all?
                        http://mindprod.com/jgloss/static.html
                        and which part of this was unclear?
                        the bit where you didn't spoon-feed him the answer
                        • 9. Re: What is static?
                          807599
                          Thanks i indeed understand now. Sorry if my logic is not as good as you guys. However i really appreciate the effort of helping me. Thanks to all.
                          • 10. Re: What is static?
                            807599
                            Thanks i indeed understand now. Sorry if my logic is not as good as you guys. However i really appreciate the effort of helping me. Thanks to all.
                            • 11. Re: What is static?
                              807599
                              Static is when you have wool socks on and you drag your feet across a room. Fun stuff indeed!
                              It is also what you get on your radio or tv if it isn't tuned correctly.
                              • 12. Re: What is static?
                                807599
                                If static variables and methods is a part of class level then why it can be inherited when i create objects.
                                • 13. Re: What is static?
                                  807599
                                  Objects are instances of classes.
                                  Static variables and methods belong to the classes, not instances(objects).

                                  The definition has been defined above also.