Java; what is static?

Discussion in 'Mac Programming' started by glossywhite, Jan 2, 2010.

  1. glossywhite macrumors 65816

    glossywhite

    Joined:
    Feb 28, 2008
    #1
    Hi all.

    Here is a very dull and useless example

    Code:
    public class myClass{
    public [B][COLOR="Red"]static[/COLOR][/B] void main(String args[]){
    System.out.println("hello world is dull");
    }
    }
    
    My question is this - is the keyword "static", defining that "main" is not an instantiated or called from an instantiated class, and therefore it is always static, and therefore always accessible and at a fixed point in memory?.

    Thanks.
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    "static" in Java means that it is part of the class itself, not of any object. It is always accessible when the class is loaded (and the class will be loaded if you try to access a static method).

    And "at a fixed point in memory" is something that is completely meaningless in Java. And when you say "always static", obviously a static thing is always static or do you mean something different with this question?
     
  3. glossywhite thread starter macrumors 65816

    glossywhite

    Joined:
    Feb 28, 2008
    #3
    Thanks, you've cleared the mental fog, and my bad regarding the ambiguity of my comment on the word static... d'oh! :p
     

Share This Page