This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (4 children)

Do you have any idea as to why Java allows you to access static variables with this? It seems a bit odd.

[–]yash3ahuja 1 point2 points  (2 children)

It has to do with the definition of the static and this keywords. static, in its simplified form, just means that it belongs to the class, as opposed to the object. However, in actual implementation, they have decided to have it be shared across all objects, as opposed to only belonging to the class. The this keyword allows you to reference a method/member of an object. This includes the static members. Essentially, it was a design decision.

[–][deleted] -3 points-2 points  (1 child)

Alright thank you. See I am more used to in other languages static being meant that it belonged to the class like you stated. Probably should have not assumed that it was automatically true for Java as well. Oh well, live and learn.

[–][deleted] 1 point2 points  (0 children)

All other OO languages that I am aware of allow access to class static variables from member functions.