I was setting out to write a piece of code today in Eclipse, and I started out like so:
public class MyClass {
System.currentTimeMillis();
}
You dont get the error with the line
long time = System.currentTimeMillis();
because you are specifying a private variable inside the class (long time) and setting them to a default value (System.currentTimeMillis()) so when you make a new instance of the class MyClass, the variable is being instantiated.
calling only System.currentTimeMillis() just has nosense, because you arent doing nothin' (neither having a context or assigning the value to a private variable)
This is illegal. In the class body you can have only: blocks, fields, constructors, methods and classes
Yours is neither. And what would you expect it to do anyway? If you want it to be executed when the class is instantiated, then place it in a block:
{
System.currentTimeMillis();
}