Results 1 to 5 of 5
  1. #1
    maknib is offline Member
    Join Date
    Nov 2010
    Posts
    90
    Rep Power
    0

    Default Static (having a hard time)

    Hello everyone.

    I have just started learning Java, i'm picking up most of it very well so far EXCEPT the word Static.

    i canno't for the life of me understand what this means or what it does.

    the reason i picked up on it was because something like this..

    Java Code:
    class MyClass{
      public static void main(String[] args){
        myMethod(4);
    
      }
      public void myMethod (int age){
        System.out.println("you are " + age " years old!");
      }
    }
    this of course threw me therror about non static methods. i know i can fix this by Making myMethod static but instead of just fixing it i would like to know Why i have to do this.

    all the articles i've read aren't making sense to me as they are using big words which i think i haven't come accross yet.

    Could anyone give me a simple explination as Why i use static and When to ouse it? do i need it on main ?

    thanks everyone (apart from this.. i LOVE java so far)

  2. #2
    maknib is offline Member
    Join Date
    Nov 2010
    Posts
    90
    Rep Power
    0

    Default

    ooooo OMG

    i think i May have just understood it..

    tell me if i'm right..

    Static is realted to the Class and not the Object.

    so if i had

    int a = 0;
    a++

    and made 5 objects they would all have the value of 1 for a

    where as if i had

    static int a = 0;
    a++

    and i made 5 objects they would have the values
    a =1
    a=2
    a-3... until the last one?


    Yes? i so hope i got this

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by maknib View Post
    ooooo OMG

    i think i May have just understood it..

    tell me if i'm right..

    Static is realted to the Class and not the Object....
    By George, I think you've got it!

  4. #4
    maknib is offline Member
    Join Date
    Nov 2010
    Posts
    90
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    By George, I think you've got it!
    Yay!!

    i can finally move on!
    Last edited by maknib; 11-02-2010 at 12:59 AM.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by maknib View Post
    Yay!!

    i can finally move on!
    The pure feeling of revelation, the sheer Eureka moment must be a great sensation ;-)

    kind regards,

    Jos

Similar Threads

  1. Replies: 7
    Last Post: 09-24-2010, 05:09 AM
  2. Replies: 3
    Last Post: 02-11-2010, 09:59 AM
  3. Extreme nooby having hard time with this app
    By asterix350z in forum New To Java
    Replies: 2
    Last Post: 12-05-2007, 07:24 PM
  4. Replies: 1
    Last Post: 08-07-2007, 05:05 AM
  5. Replies: 1
    Last Post: 08-01-2007, 09:25 PM

Posting Permissions

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