From the
Java specification:
A class body may contain declarations of members of the class, that is, fields (�8.3), classes (�8.5), interfaces (�8.5) and methods (�8.4). A class body may also contain instance initializers (�8.6), static initializers (�8.7), and declarations of constructors (�8.8) for the class.
but
obj = null;
obj2 = null;
are not declarations of a field, class, etc. They are assignments. They should be placed within one of the entities in the mentioned list.
Helpful?