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
In Java, when defining a class, you can define variables with default values and add methods. Any executable code (such as assignments) MUST be contained in a method.