in the line "que pasa" you declare a static enum variable of type Animals. But you don't assign a value. You can refer to this variable with Test.s_a because it is static. Little hint: Try this line as first line in your main method:
System.out.println(Test.s_a); // or just ...println(s_a);
Originally posted by Marc Wentink: Actually this is confusing me even more:
DOG && CAT are constant so when they're accessed, compiler will use the class name (here enum name) to replace the the reference variable. Therefore an object instance is not needed. In your example, the compiler will replace s_a.DOG to Animals.DOG. It's similar to the static variable of a class. [ August 08, 2007: Message edited by: Yeming Hu ]
OK, you know already that the static variable s_a of class Test holds null in the first place.
But what you can do in a different class (of class Test itself - doesn't matter) is assigning enums of type Animals to that variable.
In your last example you only printed out the enums themself, you did not change the contents of the variable. When you say System.out.println(s_a.DOG); the s_a refers to Animals, and with the dot operator you select DOG. But this does not change the content of variable s_a.
Try this example:
it prints: null DOG null rereference CAT DOG CAT
s_a is just a class variable (i.e. a static one) that can hold an element of Animal. At the beginning it is null, as would be any "normal" object reference, when no object is assigned to it. Then you refer the dog but not change the value of s_a. Only in the bold line, you change the value.