If I try to assign a value to a variable in a class, but outside a method I get an error.
class one{ Integer b; b=Integer.valueOf(2); }
b
A more general answer would be that the class body is about declarations, not statements. There is special provision for statements occuring in class body, but they have to be marked explicitly as either class initializers or instance initializers.