That's because "test.a;" is not a statement. If you are coming from a C background, you know that in C you can turn any expression into a statement by putting a semicolon after it:
x=y; //C and
Java syntax
x==y; //C, but not Java, syntax
The trouble with this simple approach to statements is that not all expressions make sensible statements, so Java limits the
expression ; syntax to:
; //the empty statement, if that counts
x=y; //assignment
i++;
++i;
i--;
--i; //increment and decrement
x.m(); //method invocation
new X(); //object creation
What you wrote, "test.a;", was just accessing a field, and so not a legitimate statement. Try assigning it or printing it:
int x = test.a;
//or
System.out.println(test.a);