Why include the class name when referring to a static variable?

Viewed 3863

While doing some Java homework I answered a question by writing an instance method, in the method I made use of some static final variables that belonged to the class the method was in. I wrote the static variable names without prefixing them with the class' name, for example:

for(int i=0; i < MY_STATIC_VARIABLE; i++)

instead of

for(int i=0; i < MyClass.MY_STATIC_VARIABLE; i++)

This compliled and worked correctly. It was only later that I noticed I had forgotten to prefix the class' name. Does it matter whether I include the class name or not? Does a static final variable act like a global variable within the context of its class?

7 Answers
Related