Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By gimbal2

Thread: A question about the term 'static'

  1. #1
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default A question about the term 'static'

    Ok, so, I am not new to java, and I know what static means and what it does as an access modifier.

    My question is: Why does the access modifier 'static' allow a variable or method to be called from outside of the class, this behavior seems like the complete opposite of 'static'.

    If I wasn't clear: The definition of 'static' is "lacking in movement, action, or change", some synonyms are 'fixed' and 'unchanged'. Calling the 'static' modifier allows the variable to be changed from outside of the class it is in. I just don't see the logic behind the name 'static', as it does completely the opposite of what it is defined to do.

    Anyone care to elaborate?

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,994
    Rep Power
    5

    Default Re: A question about the term 'static'

    Alas, the comparison doesn't work in this case. For what you describe Java has the keyword 'final'.

    Static in this case I guess would be closer to "the same for all instances of this class". The way that contract is fulfilled in Java is by making statics not part of the object instances, but part of the class. Hence you can refer to them without having an object instance.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: A question about the term 'static'

    Quote Originally Posted by gimbal2 View Post
    Alas, the comparison doesn't work in this case. For what you describe Java has the keyword 'final'.

    Static in this case I guess would be closer to "the same for all instances of this class". The way that contract is fulfilled in Java is by making statics not part of the object instances, but part of the class. Hence you can refer to them without having an object instance.
    Thanks for the answer, I am aware of this. I was just questioning why the name 'static' was used. I think something like 'open' would be more accurate.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,994
    Rep Power
    5

    Default Re: A question about the term 'static'

    Quote Originally Posted by zFollette View Post
    Thanks for the answer, I am aware of this. I was just questioning why the name 'static' was used. I think something like 'open' would be more accurate.
    You'd have to ask the designers of the C++ language, since it was copied from there in the Java language. Think about it: can anyone really answer the "why" questions? Better focus on what helps you progress.
    Norm likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  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 Re: A question about the term 'static'

    Especially Bjarne Stroustrup (the inventor of C++) hated new keywords; he overloaded the meaning of the word 'static' beyond repair; maybe James Gosling (the inventor of Java) suffered from the same allergy ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. question about static methods...
    By ajetrumpet in forum New To Java
    Replies: 10
    Last Post: 04-24-2013, 01:19 PM
  2. Replies: 4
    Last Post: 08-10-2012, 04:24 PM
  3. static question
    By stuckonjava in forum New To Java
    Replies: 3
    Last Post: 05-10-2012, 09:39 PM
  4. Static and non static class methods question
    By silverglade in forum New To Java
    Replies: 2
    Last Post: 05-14-2011, 10:10 PM
  5. Newbie question about Static methods
    By SCS17 in forum New To Java
    Replies: 9
    Last Post: 02-06-2008, 08:03 AM

Posting Permissions

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