Thread: Static void question:

Results 1 to 4 of 4
  1. #1 Static void question: 
    I don't take you serious
    Kastro's Avatar
    Join Date
    Nov 2008
    Posts
    2,504
    Thanks given
    92
    Thanks received
    389
    Rep Power
    604
    Yeah, how would it be written?

    Code:
    public static void
    or any other way?

    I've never made anything static so, I need to learn.

    Reply With Quote  
     

  2. #2  
    damnant quod non intellegunt

    Mr Chainsaw's Avatar
    Join Date
    Sep 2006
    Age
    30
    Posts
    4,058
    Thanks given
    827
    Thanks received
    1,277
    Rep Power
    4664
    public static void method() {
    Reply With Quote  
     

  3. #3  
    Registered Member
    PSNB's Avatar
    Join Date
    Aug 2009
    Posts
    885
    Thanks given
    8
    Thanks received
    103
    Rep Power
    590
    Static is exactly the same as a non-static method, except there's no need to instance the class to access it.

    For example, the 'players' array in the playerHandler class should be static, and not instanced through the Server class.
    Reply With Quote  
     

  4. #4  
    Hi.

    'Mystic Flow's Avatar
    Join Date
    Nov 2007
    Posts
    7,146
    Thanks given
    256
    Thanks received
    1,252
    Rep Power
    3714
    public class StaticClass {

    public static class ActionShit {
    public static void action() {
    System.out.println("Action");
    }
    }
    }


    public void doSomething() {
    StaticClass.ActionShit.action();
    }

    Btw, if your gonna put local variables in the static method, those variables have to be static aswell, along with the methods.

    And if it's not static, then you would just call an instance.



    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •