Understanding the keyword static

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muzu1232004
    New Member
    • Aug 2007
    • 16

    Understanding the keyword static

    1.Please let me know about what the static keyword means.

    2.Is it possiblle to define the static and write its method inside it such as
    static {
    some implementations ;
    }

    3.Also where does the control goes when java compiler encounters the word static ? when do we actually use static keyword.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    I simply don't believe that you don't have at least one book on Java at your disposal.
    I also don't believe that that book/those books don't explain what static members
    are all about. I do believe that you haven't read that book/those books.

    kind regards,

    Jos

    Comment

    • praveen2gupta
      New Member
      • May 2007
      • 200

      #3
      Originally posted by muzu1232004
      1.Please let me know about what the static keyword means.

      2.Is it possiblle to define the static and write its method inside it such as
      static {
      some implementations ;
      }

      3.Also where does the control goes when java compiler encounters the word static ? when do we actually use static keyword.
      Hi

      1. static keyword states that your variable is associated with the class. For example you are having one class X and
      you are instating 05 objects from this class. The 05 objects can have a different value for a single variable. But with the
      case of static variable all 05 objects will be having the same value. However each object or class can change the value
      the static varable. The value changed by one object will be reflected by all objects. Or you can understand it like a common variable for the class and all the objects of that class.

      2. Yes , you can do it. This is known as static block, which is executed once class is loaded.

      3. static can be used to count the counter of a web site, or to store the value in the static variable which is required throughout the application, etc.

      Comment

      Working...