2 Replies Latest reply: Jun 8, 2007 2:57 AM by 3004 RSS

    static local variable?

    807600
      Hi,

      Why a local variable can not be declared as static? What is the logic behind this static keyword?

      thks.
        • 1. Re: static local variable?
          807600
          static members belong to the class, not to the instance(s),
          the class with its (static) members lives in perm space (special kind of heap),
          instances live on the regular heap

          method local variables belong to the executing thread,
          thread local variables are allocated on the stack,
          thread local variables go out of scope when the method completes
          • 2. Re: static local variable?
            3004
            Hi,

            Why a local variable can not be declared as static?
            What is the logic behind this static keyword?

            thks.
            In C, a static local variable is used to maintain state between function calls. In Java, the way to maintain state is with a member variable. We have no need of static local variables.

            The meaning of the static keyword is "associated with the class as a whole, rather than with any one instance."