Difference between static and non-static.

Discussion in 'Plugin Development' started by darknesschaos, Mar 8, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    darknesschaos

    This might be a silly question, but what is the difference? There are only a few that seem obvious to me, but I would like to hear what the community has to say. Functionally they are similar, it is just I'm not so sure what each is best for. (I must have skipped that class... and Google isn't terribly helpful with this one.)
     
  2. Offline

    Nohup

    Static methods don't require you to instantiate the object they are attached to to call them, non-static do. so if I have

    Code:
    public class X
    {
      public static void Y()
      {
      ...
      }
      ...
    }
    I call this as X.Y(); However if Y is NOT static I have to do

    Code:
    X myX = new X();
    myX.Y()
    
    Now, keeping that in mind, they are VERY different. AND you can have mixed classes. BUT, if you let's say set something in the constructor, then the static method does not have access to it per se because you don't call the constructor.
     
  3. Offline

    darknesschaos

    That is the bit i understand, but the difference to me seems to mostly be if you want multiple instances of an object floating around or not.
     
  4. Offline

    Nohup

    Here's a good article.
     
  5. Offline

    darknesschaos

    Thanks! that was helpful.
     
Thread Status:
Not open for further replies.

Share This Page