Why can’t I do assignment outside a method?
original source : https://stackoverflow.com/questions/12062481/why-cant-i-do-assignment-outside-a-method
#1 answer for me
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.
#2 answer for me
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.