I found the following in the
Java Language Specification:
A class body may contain declarations of members of the class, that is, fields (�8.3) and methods (�8.4). A class body may
also contain static initializers (�8.5) and declarations of constructors (�8.6) for the class.
ClassBodyDeclaration:
ClassMemberDeclaration
StaticInitializer
ConstructorDeclaration
ClassMemberDeclaration:
FieldDeclaration
MethodDeclaration
In other words, the way I read it is that the only things the compiler will read directly in a class are Field Declaration (variable declaration)/static variable declaration & initialization and Method (including constructor) declaration.
Therefore any statements (like your "if statement" need to be in one of these (variable declaration or method declaration).
Marilyn